Atts

Atts

Anonymous
Not applicable
382 Views
5 Replies
Message 1 of 6

Atts

Anonymous
Not applicable
I am confused on something with Attribute sets. Start a assembly and place 1 component in it, then run the PlaceAtts sub below. It places a attributeset and attribute on the component occurrence. Then run the CheckAtts Sub to verify it is fine. Now in Inventor Delete the occurrence, and re-run the CheckAtts sub. Why didn't the attributes get deleted with the sub since they were attached to it? Option Explicit Public Sub PlaceAtts() Dim oDoc As AssemblyDocument Set oDoc = ThisApplication.ActiveDocument Dim oCompDef As ComponentDefinition Set oCompDef = oDoc.ComponentDefinition Dim oOcc As ComponentOccurrence Dim oAttSet As AttributeSet Dim oAtt As Inventor.Attribute Set oOcc = oCompDef.Occurrences(1) Set oAttSet = oOcc.AttributeSets.Add("MyAttSets") Set oAtt = oAttSet.Add("MyAtt", kStringType, "Testing") End Sub Public Sub CheckAtts() Dim oAttMgr As AttributeManager Dim oAttsetsEnum As AttributeSetsEnumerator Set oAttMgr = ThisApplication.ActiveDocument.AttributeManager Set oAttsetsEnum = oAttMgr.FindAttributeSets("*") Dim oAttSet As AttributeSet Dim oAtt As Inventor.Attribute For Each oAttSet In oAttsetsEnum Debug.Print oAttSet.Name Debug.Print oAttSet.Parent.Parent.Name For Each oAtt In oAttSet Debug.Print oAtt.Name Debug.Print oAtt.Parent.Parent.Parent.Name Next Next End Sub -- Kent Keller http://www.KWiKMcad.com Autodesk Discussion Group Facilitator
0 Likes
383 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Anyone? Am I just doing something wrong here or? -- Kent Keller Autodesk Discussion Forum Facilitator "Kent Keller" wrote in message news:40d2675f$1_3@newsprd01... > I am confused on something with Attribute sets. Start a assembly and > place 1 component in it, then run the PlaceAtts sub below. It places a > attributeset and attribute on the component occurrence. Then run the > CheckAtts Sub to verify it is fine. Now in Inventor Delete the > occurrence, and re-run the CheckAtts sub. Why didn't the attributes > get deleted with the sub since they were attached to it? > > > Option Explicit > > Public Sub PlaceAtts() > > Dim oDoc As AssemblyDocument > Set oDoc = ThisApplication.ActiveDocument > > Dim oCompDef As ComponentDefinition > Set oCompDef = oDoc.ComponentDefinition > > > Dim oOcc As ComponentOccurrence > Dim oAttSet As AttributeSet > Dim oAtt As Inventor.Attribute > > Set oOcc = oCompDef.Occurrences(1) > Set oAttSet = oOcc.AttributeSets.Add("MyAttSets") > Set oAtt = oAttSet.Add("MyAtt", kStringType, "Testing") > > > End Sub > > Public Sub CheckAtts() > > Dim oAttMgr As AttributeManager > Dim oAttsetsEnum As AttributeSetsEnumerator > Set oAttMgr = ThisApplication.ActiveDocument.AttributeManager > > Set oAttsetsEnum = oAttMgr.FindAttributeSets("*") > > Dim oAttSet As AttributeSet > Dim oAtt As Inventor.Attribute > > For Each oAttSet In oAttsetsEnum > Debug.Print oAttSet.Name > Debug.Print oAttSet.Parent.Parent.Name > For Each oAtt In oAttSet > Debug.Print oAtt.Name > Debug.Print oAtt.Parent.Parent.Parent.Name > Next > Next > > > End Sub > > > > -- > Kent Keller > http://www.KWiKMcad.com > > Autodesk Discussion Group Facilitator > >
0 Likes
Message 3 of 6

Anonymous
Not applicable
Kent: I have no official word but it looks like an "oversight" to me on the part of the assembly environment. It basically leaves an orphaned attribute set. I modified your code to find the orphaned sets and delete them. Maybe this will help. Public Sub CheckAtts() Dim oAttMgr As AttributeManager Dim oAttsetsEnum As AttributeSetsEnumerator Set oAttMgr = ThisApplication.ActiveDocument.AttributeManager Set oAttsetsEnum = oAttMgr.FindAttributeSets("*") Dim oAttSet As AttributeSet Dim oAtt As Inventor.Attribute For Each oAttSet In oAttsetsEnum If IsOrphanAttSet(oAttSet) Then Debug.Print oAttSet.Name For Each oAtt In oAttSet Debug.Print oAtt.Name Debug.Print oAtt.Parent.Parent.Parent.Name Next Debug.Print oAttSet.Parent.Parent.Name Else oAttSet.Delete End If Next End Sub Public Function IsOrphanAttSet(invAttSet As AttributeSet) As Boolean Dim strTemp As String On Error Resume Next strTemp = invAttSet.Parent.Parent.Name If Err.Number = 0 Then IsOrphanAttSet = True Else IsOrphanAttSet = False End If End Function -- Robert A. Williams http://www.leacar.com > Anyone? Am I just doing something wrong here or? > > -- > Kent Keller > Autodesk Discussion Forum Facilitator >
0 Likes
Message 4 of 6

Anonymous
Not applicable
Thanks Robert I was thinking of either dealing with it using a On Error Resume Next routine, or possibly using a On Delete event. I just wanted to make sure I wasn't trying to put a bandaid on something I was doing wrong in the first place ;~) -- Kent Keller Autodesk Discussion Forum Facilitator "RobertWilliams" wrote in message news:40d9ecf7_2@newsprd01... > Kent: > > I have no official word but it looks like an "oversight" to me on the part > of the assembly environment.
0 Likes
Message 5 of 6

Anonymous
Not applicable
This behavior is as expected. The problem is that in the general case, an attribute doesn't know if the object it's attached to is permanently gone or not. The case where this is the easiest to see if for B-Rep entities. Let's say you attach an attribute to the edge of a solid and then later you fillet that edge. The edge is gone but the attribute still exists. This is because the edge can come back, either by deleting the fillet feature or by moving the stop node above the fillet feature. At this point, the attribute will return the edge as its parent. Because of the unspecified lifetime of some objects, attributes are not automatically deleted. To help handle this the AttributeManager object supports the PurgeAttributeSets method that allows you to either just preview the set of attributes that currently don't have parents or actually delete them. -- Brian Ekins Autodesk Consulting Services Discussion Q&A: http://www.autodesk.com/discussion "Kent Keller" wrote in message news:40d9e5b1$1_1@newsprd01... > Anyone? Am I just doing something wrong here or? > > -- > Kent Keller > Autodesk Discussion Forum Facilitator > > > "Kent Keller" wrote in message > news:40d2675f$1_3@newsprd01... > > I am confused on something with Attribute sets. Start a assembly and > > place 1 component in it, then run the PlaceAtts sub below. It places a > > attributeset and attribute on the component occurrence. Then run the > > CheckAtts Sub to verify it is fine. Now in Inventor Delete the > > occurrence, and re-run the CheckAtts sub. Why didn't the attributes > > get deleted with the sub since they were attached to it? > > > > > > Option Explicit > > > > Public Sub PlaceAtts() > > > > Dim oDoc As AssemblyDocument > > Set oDoc = ThisApplication.ActiveDocument > > > > Dim oCompDef As ComponentDefinition > > Set oCompDef = oDoc.ComponentDefinition > > > > > > Dim oOcc As ComponentOccurrence > > Dim oAttSet As AttributeSet > > Dim oAtt As Inventor.Attribute > > > > Set oOcc = oCompDef.Occurrences(1) > > Set oAttSet = oOcc.AttributeSets.Add("MyAttSets") > > Set oAtt = oAttSet.Add("MyAtt", kStringType, "Testing") > > > > > > End Sub > > > > Public Sub CheckAtts() > > > > Dim oAttMgr As AttributeManager > > Dim oAttsetsEnum As AttributeSetsEnumerator > > Set oAttMgr = ThisApplication.ActiveDocument.AttributeManager > > > > Set oAttsetsEnum = oAttMgr.FindAttributeSets("*") > > > > Dim oAttSet As AttributeSet > > Dim oAtt As Inventor.Attribute > > > > For Each oAttSet In oAttsetsEnum > > Debug.Print oAttSet.Name > > Debug.Print oAttSet.Parent.Parent.Name > > For Each oAtt In oAttSet > > Debug.Print oAtt.Name > > Debug.Print oAtt.Parent.Parent.Parent.Name > > Next > > Next > > > > > > End Sub > > > > > > > > -- > > Kent Keller > > http://www.KWiKMcad.com > > > > Autodesk Discussion Group Facilitator > > > > > >
0 Likes
Message 6 of 6

Anonymous
Not applicable
Thanks Brian I guess it makes sense in the example you outline, ... doesn't really make sense for when you delete a part though. I will look inot using the PurgeAttributeSets method. Thanks again. -- Kent Keller Autodesk Discussion Forum Facilitator "Brian Ekins (Autodesk)" wrote in message news:40d9fb63$1_1@newsprd01... > This behavior is as expected.
0 Likes