Attribute set doesn't stick to Title Block sketchline - 2010 VBA

Attribute set doesn't stick to Title Block sketchline - 2010 VBA

alewer
Advocate Advocate
351 Views
1 Reply
Message 1 of 2

Attribute set doesn't stick to Title Block sketchline - 2010 VBA

alewer
Advocate
Advocate
Hello, all. I am attempting modify my title block with VBA. I am using attributes to mark some specific sketch lines, but when I save the title block, the attributes disappear.

I manually edit the title block definition sketch, select a sketch line, and run:

Public Sub WriteAttribute()
Dim oDrawingDocument As Inventor.DrawingDocument
Set oDrawingDocument = ThisApplication.ActiveDocument

Dim oSketchLine As Inventor.SketchLine
Set oSketchLine = oDrawingDocument.SelectSet.Item(1)

Dim oLineAttributeSets As Inventor.AttributeSets
Set oLineAttributeSets = oSketchLine.AttributeSets

Dim oLineTestAttributeSet As Inventor.AttributeSet
Set oLineTestAttributeSet = oLineAttributeSets.Add("TestAttributeSet")

Dim oLineTestAttribute As Inventor.Attribute
Set oLineTestAttribute = oLineTestAttributeSet.Add("TestName", kStringType, "TestValue")
End Sub

After running the code, I can select the line and step through the first lines of code and set a watch for oDrawingDocument.SelectSet.Item(1).AttributeSets.Count, which shows 1. This means that I've successfully created an attribute set. But as soon as I save the title block (manually), the attributes disappear: If I again manually edit the title block, select the same line, and step through the first lines of code, a watch for oDrawingDocument.SelectSet.Item(1).AttributeSets.Count shows 0. Where is my attribute set and attribute going? Am I doing something wrong, or is it impossible to get the attributes to stick?
0 Likes
352 Views
1 Reply
Reply (1)
Message 2 of 2

alewer
Advocate
Advocate
I believe I've found the solution: when creating the attributeset, I must set CopyWithOwner to True. Replace:
Set oLineTestAttributeSet = oLineAttributeSets.Add("TestAttributeSet")

with:
Set oLineTestAttributeSet = oLineAttributeSets.Add("TestAttributeSet", True)

and it seems to work.
0 Likes