Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Occurence list all

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
380 Views, 8 Replies

Occurence list all

Hello I'm trying to list all files in a assembly to write them into a database. Using different ways none gives me the correct result. Some time ago, I saw a example to count the occurences, but there I could not get the necessary informations about the single parts. The following example does not work, cause I do not find any possibilty to set the actual Occurence-Definition to give it in the subroutine as document. How can I manage this? Is there an example to do it in a proper way? * =============================== Public Sub Test1(oDoc As Inventor.Document) Dim oOcc As Inventor.ComponentOccurrence Dim DisplayName As String Dim Ct As Integer Dim iOcc As Integer For Each oOcc In oDoc.ComponentDefinition.Occurrences iOcc = iOcc + 1 DisplayName = oDoc.ComponentDefinition.Occurrences.Item(iOcc).Name If oOcc.Type = kAssemblyDocumentObject Then Debug.Print "Assembly :" & oDoc.FullFileName, DisplayName Test1 oOcc Else Debug.Print "Part : " & oDoc.FullFileName, DisplayName Test1 oOcc End If Next End Sub Roland
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

Here is an example from Autodesk University:

Public Sub AssemblyTraversal()
' Get the active document, assuming it's an assembly.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument

' Begin the assembly traversal.
Call TraverseAsm(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub

' The Level argument is used to control the amount of indent for the output.
Private Sub TraverseAsm(oOccurrences As ComponentOccurrences, Level As Integer)

' Iterate through the current list of occurrences.
Dim oOcc As ComponentOccurrence

For Each oOcc In oOccurrences

' Print the name of the current occurence.
Debug.Print Space(Level * 3) & oOcc.Name

' If the current occurrence is a subassembly then call this sub
' again passing in the collection for the current occurrence.
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call TraverseAsm(oOcc.SubOccurrences, Level + 1)
End If
Next
End Sub

// Johannes
Message 3 of 9
Anonymous
in reply to: Anonymous

Opps, such a easy thing .... Thanks, it works fine ..... Roland "dolphan" schrieb im Newsbeitrag news:25806395.1080566587294.JavaMail.jive@jiveforum1.autodesk.com... > Here is an example from Autodesk University: > > Public Sub AssemblyTraversal() > ' Get the active document, assuming it's an assembly. > Dim oAsmDoc As AssemblyDocument > Set oAsmDoc = ThisApplication.ActiveDocument > > ' Begin the assembly traversal. > Call TraverseAsm(oAsmDoc.ComponentDefinition.Occurrences, 1) > End Sub > > ' The Level argument is used to control the amount of indent for the output. > Private Sub TraverseAsm(oOccurrences As ComponentOccurrences, Level As Integer) > > ' Iterate through the current list of occurrences. > Dim oOcc As ComponentOccurrence > > For Each oOcc In oOccurrences > > ' Print the name of the current occurence. > Debug.Print Space(Level * 3) & oOcc.Name > > ' If the current occurrence is a subassembly then call this sub > ' again passing in the collection for the current occurrence. > If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then > Call TraverseAsm(oOcc.SubOccurrences, Level + 1) > End If > Next > End Sub > > // Johannes
Message 4 of 9
Anonymous
in reply to: Anonymous

I guess I'm a bit dense today since it's Monday. Can anyone point me to how I can go from a ComponentOccurence to the ComponentDefinition so I can access things like WorkPoints as in " ...ComponentDefinition.WorkPoints.Item(PointName)". I tried several variations of Occurence.Definition but all seemed to fail. I wanted to expand this macro to find and print out all the Workpoints in each occurence with XYZ's in assembly space. I have code to do the listing of XYZ's, etc, just can't seem to get there from here! TIA, Bob S. "dolphan" wrote in message news:25806395.1080566587294.JavaMail.jive@jiveforum1.autodesk.com... > Here is an example from Autodesk University: > > Public Sub AssemblyTraversal() > ' Get the active document, assuming it's an assembly. > Dim oAsmDoc As AssemblyDocument > Set oAsmDoc = ThisApplication.ActiveDocument > > ' Begin the assembly traversal. > Call TraverseAsm(oAsmDoc.ComponentDefinition.Occurrences, 1) > End Sub > > ' The Level argument is used to control the amount of indent for the output. > Private Sub TraverseAsm(oOccurrences As ComponentOccurrences, Level As Integer) > > ' Iterate through the current list of occurrences. > Dim oOcc As ComponentOccurrence > > For Each oOcc In oOccurrences > > ' Print the name of the current occurence. > Debug.Print Space(Level * 3) & oOcc.Name > > ' If the current occurrence is a subassembly then call this sub > ' again passing in the collection for the current occurrence. > If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then > Call TraverseAsm(oOcc.SubOccurrences, Level + 1) > End If > Next > End Sub > > // Johannes
Message 5 of 9
Anonymous
in reply to: Anonymous

Start going up the occurrences Parent tree. oOcc.parent -- Kent Autodesk Discussion Group Facilitator "Bob S." wrote in message news:4071bc88$1_1@newsprd01... Can anyone > point me to how I can go from a ComponentOccurence to the > ComponentDefinition so I can access things like WorkPoints as in > " ...ComponentDefinition.WorkPoints.Item(PointName)".
Message 6 of 9
Anonymous
in reply to: Anonymous

I still do not understand. You are saying that in order to get from a component occurence (oOcc) to the needed oDoc.ComponentDefinition.WorkPoints.etc that I have to access the parent of the occurence? Could you offer more of an explanation please, Kent? Would it be easier to just select all the workpoints from the assembly, if this is possible? They are in sub assemblies and components. I would need to access their component occurence name and the point name in any case. Bob "Kent Keller" wrote in message news:4071bfa0_2@newsprd01... > Start going up the occurrences Parent tree. oOcc.parent > > -- > Kent > Autodesk Discussion Group Facilitator > > > "Bob S." wrote in message > news:4071bc88$1_1@newsprd01... > Can anyone > > point me to how I can go from a ComponentOccurence to the > > ComponentDefinition so I can access things like WorkPoints as in > > " ...ComponentDefinition.WorkPoints.Item(PointName)". > >
Message 7 of 9
Anonymous
in reply to: Anonymous

My bad.... I should never post without looking at code. I was thinking of something else. Does this help get you where you want? Public Sub Parent() Dim oDoc As AssemblyDocument Set oDoc = ThisApplication.ActiveDocument Dim oCompDef As ComponentDefinition Set oCompDef = oDoc.ComponentDefinition Dim oOccs As ComponentOccurrences Set oOccs = oCompDef.Occurrences Dim oOcc As ComponentOccurrence Dim sWorkFeats As String For Each oOcc In oOccs sWorkFeats = oOcc.Definition.Document.FullFileName & " contains" & vbCrLf & vbCrLf sWorkFeats = sWorkFeats & oOcc.Definition.WorkPoints.Count & " Workpoints" & vbCrLf sWorkFeats = sWorkFeats & oOcc.Definition.WorkAxes.Count & " WorkAxis" & vbCrLf sWorkFeats = sWorkFeats & oOcc.Definition.WorkPlanes.Count & " Workplanes" MsgBox sWorkFeats sWorkFeats = "" Next End Sub -- Kent Autodesk Discussion Group Facilitator "Bob S." wrote in message news:4071c225$1_2@newsprd01... > I still do not understand. You are saying that in order to get from a > component occurence (oOcc) to the needed oDoc.ComponentDefinition.WorkPoints.etc > that I have to access the parent of the occurence? Could you offer more of > an explanation please, Kent?
Message 8 of 9
Anonymous
in reply to: Anonymous

Kent, Thanks. That works better. After seeing your code I realized that apparently my problem was the infamous error of not using "Set" to assign the ComponentDefinition from the oOcc.Definition object. Stupid error on my part. Bob "Kent Keller" wrote in message news:4071cfa6$1_2@newsprd01... > My bad.... I should never post without looking at code. I was thinking of something else. > > > Does this help get you where you want? > > Public Sub Parent() > > Dim oDoc As AssemblyDocument > Set oDoc = ThisApplication.ActiveDocument > > Dim oCompDef As ComponentDefinition > Set oCompDef = oDoc.ComponentDefinition > > Dim oOccs As ComponentOccurrences > Set oOccs = oCompDef.Occurrences > Dim oOcc As ComponentOccurrence > Dim sWorkFeats As String > > For Each oOcc In oOccs > sWorkFeats = oOcc.Definition.Document.FullFileName & " contains" & vbCrLf & vbCrLf > sWorkFeats = sWorkFeats & oOcc.Definition.WorkPoints.Count & " Workpoints" & > vbCrLf > sWorkFeats = sWorkFeats & oOcc.Definition.WorkAxes.Count & " WorkAxis" & vbCrLf > sWorkFeats = sWorkFeats & oOcc.Definition.WorkPlanes.Count & " Workplanes" > MsgBox sWorkFeats > sWorkFeats = "" > Next > > > > End Sub > > > -- > Kent > Autodesk Discussion Group Facilitator > > > "Bob S." wrote in message > news:4071c225$1_2@newsprd01... > > I still do not understand. You are saying that in order to get from a > > component occurence (oOcc) to the needed oDoc.ComponentDefinition.WorkPoints.etc > > that I have to access the parent of the occurence? Could you offer more of > > an explanation please, Kent? > >
Message 9 of 9
Anonymous
in reply to: Anonymous

Stupid mistakes are being made by everyone... I was wondering what was going wrong with this piece of code (my MsgBox was empty all the time) If Err <> 0 Then Err.Clear MsgBox Err.Description End If I banged my head a few times when I noticed the mistake :-) "Bob S." wrote in message news:407292ba$1_1@newsprd01... > Kent, > > Thanks. That works better. After seeing your code I realized that apparently > my problem was the infamous error of not using "Set" to assign the ComponentDefinition > from the oOcc.Definition object. Stupid error on my part. > > Bob > > "Kent Keller" wrote in message news:4071cfa6$1_2@newsprd01... > > My bad.... I should never post without looking at code. I was thinking of something else. > > > > > > Does this help get you where you want? > > > > Public Sub Parent() > > > > Dim oDoc As AssemblyDocument > > Set oDoc = ThisApplication.ActiveDocument > > > > Dim oCompDef As ComponentDefinition > > Set oCompDef = oDoc.ComponentDefinition > > > > Dim oOccs As ComponentOccurrences > > Set oOccs = oCompDef.Occurrences > > Dim oOcc As ComponentOccurrence > > Dim sWorkFeats As String > > > > For Each oOcc In oOccs > > sWorkFeats = oOcc.Definition.Document.FullFileName & " contains" & vbCrLf & vbCrLf > > sWorkFeats = sWorkFeats & oOcc.Definition.WorkPoints.Count & " Workpoints" & > > vbCrLf > > sWorkFeats = sWorkFeats & oOcc.Definition.WorkAxes.Count & " WorkAxis" & vbCrLf > > sWorkFeats = sWorkFeats & oOcc.Definition.WorkPlanes.Count & " Workplanes" > > MsgBox sWorkFeats > > sWorkFeats = "" > > Next > > > > > > > > End Sub > > > > > > -- > > Kent > > Autodesk Discussion Group Facilitator > > > > > > "Bob S." wrote in message > > news:4071c225$1_2@newsprd01... > > > I still do not understand. You are saying that in order to get from a > > > component occurence (oOcc) to the needed oDoc.ComponentDefinition.WorkPoints.etc > > > that I have to access the parent of the occurence? Could you offer more of > > > an explanation please, Kent? > > > > > >

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report