Hi,
I would like to show how some mechanism cooperates withsensors. Ihave developed hardware that is connected to computer viars232 andsends ASCII characters (states of sensors). Is it possibleto writea program that can connect to rs232 and SolidWorks API andforexample rotate some part of designed mechanism? I havedonesomething similar with Blender + Python but I need to do itinSolidWorks or Inventor. Maybe someone has any idea.Thanksfor any answer.SolidworksApi macros







I would like to show how some mechanism cooperates withsensors. Ihave developed hardware that is connected to computer viars232 andsends ASCII characters (states of sensors). Is it possibleto writea program that can connect to rs232 and SolidWorks API andforexample rotate some part of designed mechanism? I havedonesomething similar with Blender + Python but I need to do itinSolidWorks or Inventor. Maybe someone has any idea.Thanksfor any answer.SolidworksApi macros

Here's some code that shows how to rotate a component. Attached isa simple one component crank assembly. Run the macro and the crankwill spin around the Y axis.
Replace the code in the loop with data being read from the serialport and you should be in business.
Dim swApp As SldWorks.SldWorks
Dim mDoc As ModelDoc2
Dim assyDoc As AssemblyDoc
Dim comp As Component2
Dim trans As MathTransform
Dim v As Variant
Const PI = 3.14159265358979
Dim xRot As MathVector
Dim yRot As MathVector
Dim zRot As MathVector
Dim translation As MathVector
Dim scaleFactor As Double
Dim retval As Boolean
Sub main()
Set swApp = Application.SldWorks
Set assyDoc = swApp.ActiveDoc
Set mDoc = swApp.ActiveDoc
Dim comps As Variant
v = assyDoc.GetComponents(True)
Set comp = v(0)
Set trans = comp.Transform2
For i = 0 To 2 * PI Step (2 * PI / 360)
trans.GetData2 xRot, yRot, zRot, translation, scaleFactor
v = xRot.ArrayData
v(0) = v(0) + Cos(i)
v(2) = v(2) + Sin(i)
xRot.ArrayData = v
trans.SetData xRot, yRot, zRot, translation, scaleFactor
retval = comp.SetTransformAndSolve(trans)
mDoc.GraphicsRedraw2
DoEvents
Next i
End Sub