Opening part from drawing (API)
Opening part from drawing (API)
(OP)
I know how to get the file location of the drawing, but since the part may not be in the same location or name, I can't just strip back the file name. Is there a way to a) open the part from the drawing and/or b) find the path to the model used in the drawing?
thanks.
thanks.






RE: Opening part from drawing (API)
If the drawing is open, you can get the model used in a given view.
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: Opening part from drawing (API)
RE: Opening part from drawing (API)
I'm curious, when and how do you intend to use this function if it were to be written?
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: Opening part from drawing (API)
I need to open the part from the drawing and then save it as an IGS, sldprt and x_t in another location.
This is for PLM reasons.
RE: Opening part from drawing (API)
RE: Opening part from drawing (API)
RE: Opening part from drawing (API)
Have you written macros before? If not, this would be a tough one to start with. If you have, I'd like to see what you've started on this one.
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: Opening part from drawing (API)
CODE
Dim cfDwg As SldWorks.DrawingDoc
Dim cfMod As SldWorks.ModelDoc2
Dim cfSheet As SldWorks.Sheet
Dim cfView As SldWorks.View
Dim cfViewName As String
On Error Resume Next
Set cfDwg = aDoc 'adoc=current document, acquired elsewhere
Set cfSheet = cfDwg.GetCurrentSheet
If cfSheet Is Nothing Then GoTo cfExitStrategy
cfViewName = cfSheet.CustomPropertyView
If cfViewName <> "Default" Then
Set cfView = cfDwg.GetFirstView
Do While Not cfView Is Nothing
If cfView.Name = cfViewName Then Exit Do
Set cfView = cfView.GetNextView
Loop
If cfView Is Nothing Then GoTo cfExitStrategy
Else
On Error Resume Next
Set cfView = cfDwg.GetFirstView
Do While Not cfView Is Nothing
Set cfMod = cfView.ReferencedDocument
If Not cfMod Is Nothing Then Exit Do
Set cfView = cfView.GetNextView
Loop
If cfView Is Nothing Then GoTo cfExitStrategy
End If
Set cfMod = cfView.ReferencedDocument
txtDesc.Text = cfMod.GetCustomInfoValue("", "Description")
txtRevision.Text = cfMod.GetCustomInfoValue("", "Revision")
txtECN.Text = cfMod.GetCustomInfoValue("", "ECN")
cmdRev_Apply_Click
cfExitStrategy:
Set cfDwg = Nothing 'As SldWorks.DrawingDoc
Set cfMod = Nothing 'As SldWorks.ModelDoc2
Set cfSheet = Nothing 'As SldWorks.Sheet
Set cfView = Nothing 'As SldWorks.View
End Sub
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: Opening part from drawing (API)
RE: Opening part from drawing (API)
thanks for that snippet. I dont 100% follow it, and I am swamped with other things. I plan to study it this weekend and get crackin again on monday.
RE: Opening part from drawing (API)
If a sheet does not name a specific default view, then cfSheet.CustomPropertyView returns the string "Default". If the view has a specific name, then the code must traverse through views until it find the view with a matching name. Otherwise, it uses the view highest in the feature tree.
RE: Opening part from drawing (API)
My script runs like a champ (no error handling yet) except when I have an assembly I need to run pack and go to get the source data I need for PLM. that looks like it will be a trick in itself!