×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Opening part from drawing (API)

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.

RE: Opening part from drawing (API)

The SW Document Manager and its related objects can read a file's references without opening in SW.

If the drawing is open, you can get the model used in a given view.

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: Opening part from drawing (API)

(OP)
Can you point me in the direction?  I have looked at the API help, but it appears I am missing something. I played with some sample code but always get an error(reference?)such as "user defined type not defined"

RE: Opening part from drawing (API)

(OP)
That is true, and i guess it depends on how I gain access to the information (an array of paths, a single drawing view's path. etc)

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)

Each drawing sheet has a default view.  The user can specify a default view.  If the user has not specified a default view, the default view is the highest one on the feature tree.

RE: Opening part from drawing (API)

(OP)
This macro will mainly be used by me and a few close mechanical engineers, so I dont need absolute robustness.

RE: Opening part from drawing (API)

A piece of code from one of my macros that copies properties from a drawing sheet's deafult model.

CODE

Private Sub cmdCopyFromPart_Click()
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

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: Opening part from drawing (API)

(OP)
This is basically my first macro, but I do have some past programming experience.  It is certainly challenging.

RE: Opening part from drawing (API)

(OP)
Tick-
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)

I forgot to fully explain.  It is a command button subroutine that copies three custom properties to a drawing from its "default" part.

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)

(OP)
Just wanted to let those of you know that helped that I figured it out. I got a list of dependencies, stored them in array then checked for what file type they were. If they are parts, I run a certain routine, if they are assemblies etc.

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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources