×
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

Accessing Custom Properties from VB

Accessing Custom Properties from VB

Accessing Custom Properties from VB

(OP)
I think I have an easy one here, but we will see. I know how to get custom properties from my model when my ActiveDoc is the model: SwModel.CustomInfo2(). How do I get to the custom properties if my drawing is my ActiveDoc?

I am working in the drawing and trying to update the title block, but I am having troubles getting the info to put in the title block.

Thanks!
Joe

Here is the codes I am working with:
Public Sub SetNoteText1()

    Dim DrwDoc As SldWorks.ModelDoc2
    Dim View As SldWorks.View
    Dim Note As SldWorks.Note
    Dim NoteText As String
    Dim BoolStatus As Boolean
    Dim NoteHgt As Double
    Dim NoteAHgt As Double
    
  
    NoteAHgt = 0#
    Set DrwDoc = swApp.ActiveDoc
    Set View = DrwDoc.GetFirstView()
    Do While Not View Is Nothing
        Set Note = View.GetFirstNote()
        Do While Not Note Is Nothing
            NoteHgt = Note.GetHeight()
            NoteText = Note.GetText()
            Select Case NoteText
                Case "<COMPANY NAME>"
                    BoolStatus = Note.SetText("XYZ Co." & vbCrLf & vbCrLf & "COMPOSITE BEAM")
                Case "<DRW>"
                    BoolStatus = Note.SetText("AUTO")
                Case "<Order Number>"
                    BoolStatus = Note.SetText(Word)
                Case "WEIGHT:"
                    BoolStatus = Note.SetText("WEIGHT:  X LB")
                Case "A"
                    NoteAHgt = NoteHgt
                    BoolStatus = Note.SetText("A   " & "   NB  001")
                Case Else
            End Select
            Set Note = Note.GetNext()
        Loop
        Set View = View.GetNextView
    Loop

End Sub

RE: Accessing Custom Properties from VB

The easiest way to update title block based on part custom properties is to make your drawing template with notes linked to model custom properties.  But that's not what you're asking.

Now, if you want to get part (or assembly) custom properties while a drawing is the active document, all you have to do is get a pointer to the referenced document.    Declare another ModelDoc2 object variable.  I'll call it swTargetDoc.  After your line

Set View = DrwDoc.GetFirstView()

put

If Not View.IsModelLoaded Then
   View.LoadModel
End If
Set swTargetDoc = View.ReferencedDocument

Now you can access swTargetDoc's custom properties just like you would if it was the active doc.

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