Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Accessing Custom Properties from VB

Status
Not open for further replies.

JoeMoss

Mechanical
Mar 8, 2006
37
0
0
US
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
 
Replies continue below

Recommended for you

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.

 
Status
Not open for further replies.
Back
Top