HI I have to change the shape of tubing ( xxx. SLDPRT part ) that are made with a WELDMENT / STRUCTURAL MEMBER with MACRO in vb.NET . I think I have to use the LibraryFeatureData but I don't knows how to use it. I found that exermple (http://help.solidworks.com/2010/english/api/sldworksapi/Get_Library_Feature_Data_Example_VBNET.htm) but it don't work.
In other word, I have to know the the .SLDFLFD used by a STRUCTURAL MEMBER feature, and change it.
Also, what the difference between the GETxxxxx member and the IGET... member.
ThanK for youy help
SolidworksApi macros
Hi
I found the way to get the WeldmentProfilePath ( .sldlflp file ) of a structural member. But whe i change the value ( with a valid one ) my model is not updated.
Can someone help me.
this is my code
Dim swModel As IModelDoc2
Dim swModelDocExt As IModelDocExtension
Dim swSelMgr As ISelectionMgr
Dim swWeldFeat As IFeature
Dim swWeldFeatData As IStructuralMemberFeatureData
Dim boolstatus As Boolean
swModel = swApp.ActiveDoc
swSelMgr = swModel.SelectionManager
swModelDocExt = swModel.Extension
boolstatus = swModelDocExt.SelectByID2(
"Structural Member1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
swWeldFeat = swSelMgr.GetSelectedObject6(1, 0)
swWeldFeatData = swWeldFeat.GetDefinition
swWeldFeatData.AccessSelections(swModel,Nothing)
swWeldFeatData.WeldmentProfilePath ="E:\temp\p\a\3 x 2 x 0.25.sldlfp"
swModel.EditRebuild3() ' this line don't update the model
ps1, how to insert code in a sub-windows in the message
ps 2 excuse my englis, i'am a french guy
Make sure you have the Weldment profile path added under Tools > Options > File Locations and try these codes (taken from SW API help)
<p>Option Explicit</p><p></p><p>Dim swApp As SldWorks.SldWorks</p><p>Dim swModel As SldWorks.ModelDoc2</p><p>Dim swModelDocExt As SldWorks.ModelDocExtension</p><p>Dim swSelMgr As SldWorks.SelectionMgr</p><p>Dim swWeldFeat As SldWorks.Feature</p><p>Dim swWeldFeatData As SldWorks.StructuralMemberFeatureData</p><p>Dim boolstatus As Boolean</p><p></p><p>Sub main()</p><p>Set swApp = Application.SldWorks</p><p>Set swModel = swApp.ActiveDoc</p><p>Set swSelMgr = swModel.SelectionManager</p><p>Set swModelDocExt = swModel.Extension</p><p>boolstatus = swModelDocExt.SelectByID2("Structural Member1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)</p><p></p><p>Set swWeldFeat = swSelMgr.GetSelectedObject6(1, 0)</p><p>Set swWeldFeatData = swWeldFeat.GetDefinition</p><p>swWeldFeatData.AccessSelections swModel, Nothing</p><p>swWeldFeatData.WeldmentProfilePath = "Put the complete path here"</p><p>boolstatus = swWeldFeat.ModifyDefinition(swWeldFeatData, swModel, Nothing)</p><p></p><p>End Sub</p>hi
Thanks for your help Deepak. I add the ''swWeldFeat.ModifyDefinition '' line but it change nothing.
someone have another ideas.
dan
Make sure you have a part that has a feature named Structural Member1 to make this macro work or change the feature name as per the file.
My feature is named corretly . When i run the code in STEP INTO I see the feature selection in SOLIDWORKS. After, if manually edit my feature in Soldworks, I see in the EDIT FEATURE windows that the profil name have changed , but not my part.
the profil that i use exist. I cut & paste the name to be sure to have the good speeling.
bizard!!!
Daniel, your code seems fine, but you need to run the ModifyDefinition Method to apply the profile. If you tried this already and it still didn't work, make sure the path to your file is correct, and that is it in the correct format. It appears that this file is saved over the network (E:\), which also could be a problem. Try getting the macro running on the local drive first, preferably with a solidworks weldment profile template....under\Data\Weldment profiles\ .
I tested this code and it works fine for me....
<p></p><div id="_mcePaste"> Public Sub main()</div><div id="_mcePaste"> </div><div id="_mcePaste"> Dim swModel As IModelDoc2</div><div id="_mcePaste"> Dim swSelMgr As ISelectionMgr</div><div id="_mcePaste"> Dim swWeldFeat As IFeature</div><div id="_mcePaste"> Dim swWeldFeatData As IStructuralMemberFeatureData</div><div id="_mcePaste"> Dim boolstatus As Boolean</div><div id="_mcePaste"> </div><div id="_mcePaste"> swModel = swApp.ActiveDoc</div><div id="_mcePaste"> swSelMgr = swModel.SelectionManager</div><div id="_mcePaste"> boolstatus = swModel.Extension.SelectByID2("Structural Member1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)</div><div id="_mcePaste"> </div><div id="_mcePaste"> swWeldFeat = swSelMgr.GetSelectedObject6(1, 0)</div><div id="_mcePaste"> swWeldFeatData = swWeldFeat.GetDefinition</div><div id="_mcePaste"> swWeldFeatData.AccessSelections(swModel, Nothing)</div><div id="_mcePaste"> </div><div id="_mcePaste"> swWeldFeatData.WeldmentProfilePath = "C:\Program Files\SolidWorks Corp\SolidWorks\data\weldment profiles\ansi inch\c channel\3 x 5.sldlfp"</div><div id="_mcePaste"> 'swWeldFeatData.WeldmentProfilePath = "C:\Program Files\SolidWorks Corp\SolidWorks\data\weldment profiles\ansi inch\pipe\0.5 sch 40.sldlfp"</div><div id="_mcePaste"> 'swWeldFeatData.WeldmentProfilePath = "C:\Program Files\SolidWorks Corp\SolidWorks\data\weldment profiles\ansi inch\angle iron\1 x 1 x 0.125.sldlfp"</div><div id="_mcePaste"> 'swWeldFeatData.WeldmentProfilePath = "C:\Program Files\SolidWorks Corp\SolidWorks\data\weldment profiles\ansi inch\rectangular tube\4 x 3 x 0.25.sldlfp"</div><div id="_mcePaste"> </div><div id="_mcePaste"> boolstatus = swWeldFeat.ModifyDefinition(swWeldFeatData, swModel, Nothing)</div><div id="_mcePaste"> </div><div id="_mcePaste"> End Sub</div><br><p></p>Hope this helps,
Filipe
Macro works fine for me (check attached video). Can you record a video of what you see on the screen.
Also upload a sample file on which the macro doesn't work.
thank's for your help but on my computer, it's not working.
This is a video capture of my screen. Tomorow, i will try on another computer.
dan
Hey Dan, you're welcome, no problem!
What SW version are you running? Do you have the latest service pack installed?
I can't seem to be able to play the video you uploaded...it's some special codec that I've never seen before.
Cheers
Filipe
Hi
I make my video capture withg a small freeware. The codec is INTEL INDEO VIDEO 4.1. I try the code on 2 computer, it make the same thing. Both have solidworks 2009 1 1 with service pack 0 ( win xp ) and the other with service pack 1 ( win 7 )
It's wierd. Itchange the profil , I see it when I EDIT FEATURE, but the model don't change
dan
It might be a service pack bug...try updating to the last available service pack, or preferably update to sw2011.