当前位置:文档之家› OptisWorks_2010_Automation_User_Guide_14737

OptisWorks_2010_Automation_User_Guide_14737

OptisWorks_2010_Automation_User_Guide_14737
OptisWorks_2010_Automation_User_Guide_14737

OPTISWORKS 2010

Automation User Guide

OPTIS

BP 275 - 83078 TOULON Cedex 9

FRANCE

Tel.: +33 494 086 690

Fax: +33 494 086 694

https://www.doczj.com/doc/ad16206878.html,

COPYRIGHT NOTICE

All rights reserved. No part of this publication may be reproduced, storied in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the written permission of OPTIS, BP 275 - 83078 TOULON Cedex 9, FRANCE.

Table Of Contents

What is Automation (1)

General description (1)

Technical description (1)

Development tools (1)

Automation in OptisWorks (3)

Using OptisWorks Add-In or OptisWorks Studio (3)

Calling OptisWorks APIs (4)

Getting Started Automation (5)

Getting Started Automation (5)

First macro step 1: Creation by recording events (5)

First macro step 2: Modification of an existing macro (12)

First macro step 3: Presentation of the results (15)

Second macro step 1: Creation of a new macro (17)

Second macro step 2: Optimization algorithm (19)

Second macro step 3: Presentation of the results (23)

APIs (26)

OptisWorks API Index (26)

OptisWorks3DTextures (26)

OptisWorksCatalog (27)

OptisWorksDetectors (27)

OptisWorks Detector Interfaces (29)

OptisWorksDirectSimulation (33)

OptisWorksFaces (39)

OptisWorksInstance (42)

OptisWorksInverseSimulation (46)

OptisWorksPartPreferences (49)

OptisWorksSurfaceSource (52)

Known Problems and Limitations 2010 (56)

Known Problems (56)

Limitations (59)

Trademarks (61)

What is Automation

This page describes what is automation.

General description

Automation is a powerful tool that allows you to communicate with any Windows applications. Automation can replace the old specific macro way method for writing script.

Using Automation you will be able to:

?Write script using any language compatible with Automation (VB Script, C++...),

?Directly access results data without knowing specific format (like XMP file),

?Write your own HTML reports that automatically analyze the results,

?Write your own optimization code...

Technical description

Automation is based on COM (Component Object Model). This is a standard way to describe the interface exposed by a Windows application to other Windows

applications.

The interface is described using the IDL (Interface Description Language). This

interface is used to give the description of all data and functions (and their

parameters) that can be called from another application.

The exposed data are called Properties.

The exposed functions are called Methods.

Development tools

If you want to use Automation you need to decide which language to use depending on your needs.

For basic needs the VB Script or VBA language is the easiest to understand and to use for a non-developer. You can use VB Script in HTML file. You can use FrontPage for editing the HTML file.

VB Script or VBA is also included in a lot of software like SolidWorks. When you

write a macro with this software, the VB Script language is used. So it is very easy to write macro that mix CAD VB Script or VBA instructions and Virtual Photometric Lab VB Script instructions : using your own merit function you have your own

OptisWorks 2010 - Automation User Guide

optimization tool.

For more complex needs you need to use C++, which is a more difficult to learn language for non developers.

The following SolidWorks web page gives you advices, code fraction and API functions' examples: https://www.doczj.com/doc/ad16206878.html,/api.

Automation in OptisWorks

Automation in OptisWorks allows the user to launch simulations, get the results and load them.

Automation in OptisWorks requires OPTIM1.

OptisWorks Automation includes functions giving access to data.

This section of the OptisWorks help includes:

? A "Getting Started" section that will give an overview of what OptisWorks Automation can achieve with 2 examples of Visual Basic script ?The description of all the OptisWorks APIs.

All examples are given using VB Script language but any other language compatible with Automation can be used.

To open a SolidWorks macro, select "Tools", "Macro" and "Edit".

What OptisWorks APIs can achieve:

?Change sources' configuration (for example flux, type of spectrum...) ?Change the part preferences (internal/external materials, surface quality)

?Launch illuminance and luminance simulations (Direct and Inverse simulations)

OptisWorks APIs can be used with OptisLabs Automation to analyse the results (see OptisLabs Automation Index page or OptisLabs OnLine Help)

Using OptisWorks Add-In or OptisWorks Studio

In order to modify the properties of a part or to launch simulations, the scrip needs to access first to the SolidWorks application to then modify the active document (part or assembly).

However, the access to the SolidWorks application is not the same according to the version of OptisWorks used. The two different codes are presented below:

For OptisWorks Add-In:

Dim swApp As Object

Set swApp = Application.SldWorks

For OptisWorks Studio:

Dim swApp As Object

Set swApp =

OptisWorks 2010 - Automation User Guide

GetObject(Class:="OptisWorksStudio.Application") Calling OptisWorks APIs

The first step is to check the references Microsoft Visual Basic is going to use

to execute the script. To do so, select "Tools", "References". In addition to the SolidWorks references, you will have to select "OptisWorks Catalog 1.0 Type

Library" and "OptisWorks script 1.0 Type Library".

If those references are not in the list, select "Browse". Go to the OPTIS folder, "OptisWorks 200X" (according to the version you use). You will find a first dll

named "OptisWorksCatalog.dll" you need to select. It corresponds to the

reference "OptisWorks Catalog 1.0 Type Library"

Repeat the previous steps. If you are using a 32 bits version of the software,

you need to select a second dll named "OptisWorks.dll". In case of a 64 bits

version, go to "OW64" folder to find "OptisWorks.tlb". They correspond to the reference "OptisWorks script 1.0 Type Library".

Before using any OptisWorks methods, it is important to use the following

instruction:

Set Catalog =

CreateObject("OptisWorksCatalog.Catalog")

This instruction automatically runs Catalog to create an instance of the

application. The APIs need then to refer to the variable "Catalog". The

Following example shows the use of Catalog to create the instance (Instance) referring to the active document of SolidWorks (ModelDoc):

Set Instance = Catalog.Find(ModelDoc)

Set PartPreferences=Instance.GetPartPreferences()

The object PartPreferences is then defined using Instance as been a

GetPartPreferences object.

Note that there is no reference to the location of Catalog on the disk. It is

because, as an Automation application, it has been registered in the Windows' registry, linking the application we want to reach with

"OptisWorksCatalog.Catalog".

Getting Started Automation Getting Started Automation

The aim of the following tutorial is to give the user a first experience of what the

OPTIM1 option can achieve.

The user will learn how to access to an existing OptisWorks 2007 simulation

feature and how to update it from a script, as well as controlling the OPTIS XMP

Viewer application using a script. Finally, this tutorial will show how to interact

between OptisWorks 2007 and the OPTIS XMP Viewer using the same script.

OptisWorks 2008 Add-In or Studio can be used.

LM2, OPTIM1 and COL are required.

1h30min

The user is going to generate a first macro from scratches creating the image of a

blackbody at different temperature between 1000K and 12500K.

?First macro, Step 1: creation by recording events

?First macro, Step 2: modification of an existing macro

?First macro, Step 3: presentation of the results

Then a second script will be written to optimize the temperature of a blackbody to

reduce the difference between its colour and a given colour.

?Second macro, Step 1: creation of a new macro

?Second macro, Step 2: optimization algorithm

?Second macro, Step 3: presentation of the results

First macro step 1: Creation by recording events

This step shows how to record events and create a macro.

1. First, open the assembly named "GS_SurfaceSource".

This assembly contains:

? A source part named "source1" that represents a blackbody with the temperature of 1000°K.

? A Luminance detector named "LumMeter".

OptisWorks 2010 - Automation User Guide

Because the temperature of the blackbody can only be changed within the part

containing the source, we need to record the procedure to select the part, open it and

then rebuilt the assembly.

This next step will give us the SolidWorks script that we are going to modify by writing

manually the OptisWorks APIs to change the source temperature and proceed an inverse simulation to get luminance data.

2. Select "Tools", "Macro", "Records".

Getting Started Automation

OptisWorks 2010 - Automation User Guide

3. Then select the part named SurfaceSource (containing the source) and right click on

it. Select "Open Part".

Click on the part name in the Feature Management Design Tree.

Getting Started Automation

4. To reactivate the assembly, click on Window and select the assembly named

GS_SurfaceSource.

5. You can then stop the recording by either clicking on the stop icon as shown on the screen print below or selecting "Tools", "Macro", "Stop".

OptisWorks 2010 - Automation User Guide

You can save your macro, for example by naming it "AutomationMacro1.swp".

6. To edit your new macro, you can either click on the Edit icon of the Macro tool box or

selecting "Tools", "Macro" and "Edit".

Getting Started Automation

7. After selecting your macro, SolidWorks opens Microsoft Visual Basic so you can visualize the script of the events you have just recorded.

Let us add some comments on the script to decrypt it and suppress the unwanted lines.

OptisWorks 2010 - Automation User Guide

First macro step 2: Modification of an existing macro

This step shows how to update the macro to:

?Change the temperature of the blackbody source

?Run an inverse simulation to get luminance data

?Save luminance data as an image

1. Changing the temperature of the source

to execute your script. To do so, select "Tools", "References". In addition to the

SolidWorks references, you will have to select "OptisWorks Catalog 1.0 Type Library" and "OptisWorks script 1.0 Type Library".

Getting Started Automation

In case these references are not in the list, click on the "Brows" button, go to the "OPTIS" folder and "OptisWorks 2009" folder. Select "OptisWorksCatalog.dll". For 32 bits operating system version, select also "OptisWorks.dll". For 64 bits operating system version, go to "OW64" folder and select "OptisWorks.tlb".

Before modifying the script, we need to declare some variables to use the OptisWorks APIs.

OptisWorks 2010 - Automation User Guide

Note that for OptisWorks Studio, the definition of swApp is different: Set swApp =

GetObject(Class:="OptisWorksStudio.Application")

As the temperature will change between 1000 and 12500°K, we use a For loop that will increment the temperature by 500°K steps. Then, we use OptisWorks APIs to modify the temperature of the source, placing the script just before the assembly reactivation part.

2. Inverse simulation

Again, the following code uses OptisWorks APIs to run inverse simulation and get the

Getting Started Automation luminance data for each temperature of the loop steps.

3. Save luminance data as an image

To finish the script, we want to save the data from the inverse simulation as a jpeg image. To do so, we need to use some APIs from OptisLabs' Virtual Photometric Lab.

Make sure the path to save the images is correct.

First macro step 3: Presentation of the results

This step shows how to run the macro and how to get the result.

1. Select "Tools", "Macro", "Run" to execute the macro.

OptisWorks 2010 - Automation User Guide

2. Explore the "Images" directory, and select "View Thumbnails".

相关主题
文本预览
相关文档 最新文档