Hi all.
Three days ago I used method AddComponents3 to add a number of components into assembly with defined translation vectors. Everything was fine as long as I remember. As a guide I used this example http://help.solidworks.com/2014/English/api/sldworksapi/Add_Components_Example_VB.htm
Two next days I was massaging the VBA macro and when I finally finished it and reran it, the translation stopped to work. So I have written a simple trial macro again but to my surprise it doesn't work!
As a part I simply create a cube with 1mm sides. At a one corner I define the Coordinate System named CS2. After submitting the macro shown below, the cubes is placed into the assembly with the CS2 coinciding with the assembly origin. Please does anyone know why is not the cube moved by 0.002 mm in Z-axis as defined in translation vector in the transformation matrix?? What is wrong with the macro?
Thanks
Milan
===
Dim swApp As SldWorks.SldWorks
Dim assemb As SldWorks.IAssemblyDoc
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim compNames(0) As String
Dim compXforms(15) As Double
Dim compCoordSysNames(0) As String
Dim vcompNames As Variant
Dim vcompXforms As Variant
Dim vcompCoordSysNames As Variant
Dim vcomponents As Variant
Sub main()
Set swApp = Application.SldWorks
Set assemb = swApp.NewDocument("C:\ProgramData\SolidWorks\SolidWorks 2011\templates\Assembly.asmdot", 0, 0, 0)
swApp.ActivateDoc2 assemb.GetTitle, False, longstatus
compNames(0) = "D:\TheCars\3D\SolidWorksModels\cube.SLDPRT"
' Define the transformation matrix. See the IMathTransform API documentation.
' Add a rotational diagonal unit matrix (zero rotation) to the transformation matrix
compXforms(0) = 1#
compXforms(1) = 0#
compXforms(2) = 0#
compXforms(3) = 0#
compXforms(4) = 1#
compXforms(5) = 0#
compXforms(6) = 0#
compXforms(7) = 0#
compXforms(8) = 1#
' Add a translation vector to the transformation matrix
compXforms(9) = 0#
compXforms(10) = 0#
compXforms(11) = 0.002
' Add a scaling factor to the transform
compXforms(12) = 1#
' The last three elements of the transformation matrix are unused
' Register the component's coordinate system name
compCoordSysNames(0) = "CS2"
' Add the component to the assembly.
vcompNames = compNames
vcompXforms = compXforms
vcompCoordSysNames = compCoordSysNames
vcomponents = assemb.AddComponents3((vcompNames), (vcompXforms), (vcompCoordSysNames))
End Sub
===