I am trying to write a macro in Solidworks (2015) to take a large group of .STL files, load them into Solidworks, and align them in an assembly.
Initially, I recorded a macro on solidworks of me doing just that. I would load a .STL file, create an assembly from it, then load other .STL files, save them, then add them to the assembly. The files would align perfectly by themselves (I think by using their relative position to the origin).
The recorded code to load the files looked like this:
boolstatus = Part.AddComponent(".SLDPRTfilelocation", -8.034...E-05, 1.036...E-04, -2.799...E-05)
What is interesting about this recorded code is: 1) Trying to run the recorded code doesn't work (the
.AddComponent command doesn't seem to work unless I close the file then open it again with
.OpenDoc6). 2) When a part is added to the assembly using
.AddComponent it requires the x,y,z coordinates of the geometric centre of the part it is adding. When I record the macro of putting the parts into the assembly by hand one-at-a-time I can see the coordinates of the geometric centres of the .STL files.
The files perfectly align in the assembly using these values so it's safe to assume they are correct.
How does Solidworks determine these coordinate values? Is there any code I can use to determine them?