How to handle SolidWorks arrays

<< Click to Display Table of Contents >>

Navigation:  Programming Mechworks PDM > DBWCommandShell > Examples >

How to handle SolidWorks arrays

Since SolidWorks arrays are strongly typed, it is impossible to read/write arrays of data directly from a script, wiche is sometimes necessary in SolidWorks API calls. DBworks includes the COM object MWScriptGUI.VariantTranslator that performs data translation enabling you to call such APIs from script.

Reading Arrays of Doubles retrieved from SolidWorks API calls

Syntax

Set translator = CreateObject("MWScriptGUI.VariantTranslator")

DepenArray = translator.makeReadable(SldWork_array)

 

Example

The following example retrieves all the documents depending (at level 1) from the current document.

sub main()

Dim Model
Dim HowManyDocs
Dim ListOfDocs
Dim DocName, message
Dim i, count
Dim translator
res=DBWGetAssemblyDependencies (ListOfDocs )
if res=True then
 for i= 0 to ubound(listofdocs) step 2
  DBWMsgBox listofdocs(i) ' shows the simple name for the first component (readable!)
 next
end if
end sub
function DBWGetAssemblyDependencies (byref DepenArray )
Set Model = swApp.ActiveDoc   ' Get the active document
if Model Is Nothing then
 DBWGetAssemblyDependencies=False
 exit function
end if
if Model.GetType()<>2 then
  DBWGetAssemblyDependencies=False
 exit function
end if
HowManyDocs = Model.GetNumDependencies(false,false)   ' True to get all sub documents and to
DBWMsgBox howmanydocs ' displays the number of subcomponents
' the translator gets a variant from SolidWorks and returns a variant fully readable from VBScript
Set translator = createObject("MWScriptGUI.VariantTranslator")
DepenArray  = translator.makeReadable(Model.GetDependencies(false,false)) ' get the dependencies for level 1
set translator = nothing ' Don't need the translator anymore
DBWGetAssemblyDependencies=True
end function


Reading Arrays of Objects retrieved from SolidWorks API calls

This method allows you to have access to objects inside arrays returned from SolidWorks API calls

Syntax

Set MWObj = CreateObject("MWScriptGUI.VariantTranslator")

ObjArray = MWObj.makeReadableForArraysOfObjects(SldWork_array)


Sending Arrays of Double as parameters in SolidWorks API calls

This method allows you to make API calls that require passing as parameters arrays of Double

Syntax

Set MWObj = CreateObject("MWScriptGUI.VariantTranslator")

DoubleArray = MWObj.toArrayOfDouble(scriptVariable)