Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weldment API Problem in Windows 7 x64

Status
Not open for further replies.

packmen

Mechanical
Aug 31, 2001
77
0
0
BR
Hi, I know this is pretty new but I am using solidworks 2009 SP3 in windows 7 Build 7100 and a macro , the same one the api help files shows as an example, stop workind in this windows, even in vista x64 it works, Is there anyone with the same problem or maybe a solution. The code is this one.

thanks.

Option Explicit



Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swModelDocExt As SldWorks.ModelDocExtension

Dim swSelMgr As SldWorks.SelectionMgr

Dim swWeldFeat As SldWorks.Feature

Dim swWeldFeatData As SldWorks.StructuralMemberFeatureData

Dim boolstatus As Boolean



Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

Set swModelDocExt = swModel.Extension

boolstatus = swModelDocExt.SelectByID2("Structural Member1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)



Set swWeldFeat = swSelMgr.GetSelectedObject6(1, 0)

Set swWeldFeatData = swWeldFeat.GetDefinition

swWeldFeatData.AccessSelections swModel, Nothing

**************************************************************
it stop working in this line !!!!!!!
**************************************************************

swWeldFeatData.WeldmentProfilePath = "C:\Program Files\SolidWorks_2006_sp0\data\weldment profiles\iso\pipe\26.9 x 3.2.sldlfp"

boolstatus = swWeldFeat.ModifyDefinition(swWeldFeatData, swModel, Nothing)



End Sub
 
Replies continue below

Recommended for you

I found this too but couldn't understand, i have vista and win7 in the same computer and I tested the code on both, I was looking for a alternative, what i reaaly want is to change the weldment profile, if there is other ways I just need the vb command, the rest i can figure it out. thanks for helping, I tried to record a macro to see how it is done, but if I run the recorded macro it doesn't work..
 
When you declare a variable in VBA, you use the statement

Dim [varname] As [vartype]

When you declare an object variable, you can either tell VBA straight up what type of object you expect, like

Dim swApp As SldWorks.Application

or you can let VBA figure it out on its own by declaring like

Dim swApp As Object.

This makes VBA figure out what kind of object it has once it gets it.

If you use the second method, it's called "late binding". The first method is called "early binding". Each has its pros/cons.

-handleman, CSWP (The new, easy test)
 
make assembly from your part first

'-------------------------------------------------
'
' Preconditions: Assembly document open that has part with a feature named Structural Member1.
'
' Postconditions: Profile changed to profile specified in macro.
'
'--------------------------------------------------
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swSelMgr As SldWorks.SelectionMgr
Dim swWeldFeat As SldWorks.Feature
Dim swWeldFeatData As SldWorks.StructuralMemberFeatureData
Dim boolstatus As Boolean
Dim swComp As SldWorks.Component2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swModelDocExt = swModel.Extension
'select your structural member
Set swWeldFeat = swSelMgr.GetSelectedObject6(1, 0)
Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, 0)

Set swWeldFeatData = swWeldFeat.GetDefinition
swWeldFeatData.AccessSelections swModel, swComp
swWeldFeatData.WeldmentProfilePath = "C:\Program Files\SolidWorks_2006_sp0\data\weldment profiles\iso\pipe\26.9 x 3.2.sldlfp"
boolstatus = swWeldFeat.ModifyDefinition(swWeldFeatData, swModel, swComp)

End Sub

 
It gives the folowing error.


error '-2147417551 (80010105)':
Automation Error

when trying to execute
swWeldFeatData.WeldmentProfilePath = "C:\Program Files\SolidWorks_2006_sp0\data\weldment profiles\iso\pipe\26.9 x 3.2.sldlfp"

P.S: I changed the Path to a valid one.

Debug.Print Err returned -2147417851

 
I Use it to create new parts via API. I open some custom parts eatch with his own drawing already made. I don't see how can I use in assembly this way. The idea is to automate the process of creating parts, it acess a data base to get a newcode and the weldment profiles to change "Base Parts" I already created, is like a shaft frequently used, so my base parts already have keyways and holes, in this process i used to change the profile, now i pause the macro to do it manualy then macro continues from this point, very furstating.. but thanks for the efford, maybe I can find an alternative knowing that in assemblies it work.
 
if you are creating new part you can also create temporary dummy assembly and put your part in there, for changing profile path and save your part and throw assy away.
 
there is also difference between model created in sw2008 and converted to 2009 and new created weldment in 2009. Another property sheet of structural member. Converted is missing groups and is crashing by weldmentprofilepath command.
 
uhuuuuuuuuuuuuuuuuuuuuuuuu \o/

Yes I am happy and yes there is a conversion problem..
All I have to do is make the base parts again but those are very easy to do...

Thank you a lot!!!!!

:)
 
Status
Not open for further replies.
Back
Top