set part (visual basic - solidworks)
set part (visual basic - solidworks)
(OP)
I am trying to edit a SW part using Microsoft Visual Basic. I just want to edit some dimensions. The code I am using is the following:
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Set myDimension = Part.Parameter("dimension2@Sketch2")
myDimension.SystemValue = Excel.Range("C4") * 0.001
Set myDimension = Part.Parameter("dimension1@Sketch2")
myDimension.SystemValue = Excel.Range("C3") * 0.001
Set myDimension = Part.Parameter("dimension3@Sketch3")
myDimension.SystemValue = Excel.Range("C5") * 0.001
Part.ClearSelection2 True
boolstatus = Part.ForceRebuild3(True)
The problem I have is using "Set Part = swApp.ActiveDoc" because I can only edit an active part. This gives me 2 main problems:
- I can't edit a part that is not active/opened.
- If I open more than one part with the same name of the dimensions, all the parts are changed. (I know I could solve this just changing the names of the dimensions, but I don't want to).
What I would like to do is put some kind of reference to "set part" in order to change the part I want and not an active part.
I hope I have explained in a good way my problem... Thank you for your help!
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Set myDimension = Part.Parameter("dimension2@Sketch2")
myDimension.SystemValue = Excel.Range("C4") * 0.001
Set myDimension = Part.Parameter("dimension1@Sketch2")
myDimension.SystemValue = Excel.Range("C3") * 0.001
Set myDimension = Part.Parameter("dimension3@Sketch3")
myDimension.SystemValue = Excel.Range("C5") * 0.001
Part.ClearSelection2 True
boolstatus = Part.ForceRebuild3(True)
The problem I have is using "Set Part = swApp.ActiveDoc" because I can only edit an active part. This gives me 2 main problems:
- I can't edit a part that is not active/opened.
- If I open more than one part with the same name of the dimensions, all the parts are changed. (I know I could solve this just changing the names of the dimensions, but I don't want to).
What I would like to do is put some kind of reference to "set part" in order to change the part I want and not an active part.
I hope I have explained in a good way my problem... Thank you for your help!






RE: set part (visual basic - solidworks)
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: set part (visual basic - solidworks)
RE: set part (visual basic - solidworks)
Like this (I usually do things the long way but you should get the idea):
Dim theModel as sldWorks.ModelDoc2
Set swApp = CreateObject("SldWorks.Application")
Set theModel=swApp.ActiveDoc
'' Now just set the Part object equal to theModel object
set Part=theModel
HTH,
Dan
RE: set part (visual basic - solidworks)
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Part.Parameter("dimension1@Sketch1@Actuator1.1.Part").SystemValue = Excel.Range("C5") * 0.001
Part.Parameter("dimension2@Sketch1@Actuator1.1.Part").SystemValue = Excel.Range("C6") * 0.001
boolstatus = Part.ForceRebuild3(True)