Inventor General Discussion

Inventor General Discussion

Reply
Active Member
abrink100
Posts: 6
Registered: ‎02-26-2013
Message 1 of 6 (270 Views)
Accepted Solution

IV2012 API - AddCircularPattern doen't work with Axis from Part in Assembly

270 Views, 5 Replies
02-26-2013 04:25 AM

Hello,

 

There are two cases, that should behave the same, but they don't.

First program works normally. Inventor generates a circular Pattern with the given Part.

 

' Part referenced in Obejct-Collection-Object

o_ObjectCollection (is defined)

 

' reference an Axis of the Assembly

Dim o_AssyDef As AssemblyComponentDefinition

o_AssyDef = o_AssyDoc.ComponentDefinition
Dim o_WorkAxis As WorkAxis
o_WorkAxis = o_AssyDef.WorkAxes(3)

' Add Circular Pattern with Axis from Assembly

Dim o_CircOccPatt As CircularOccurrencePattern
o_CircOccPatt = o_AssyDef.OccurrencePatterns.AddCircularPattern _
        (o_ObjectCollection, o_WorkAxis, True, "90 deg", 3)

 

 

 

Now, the second case, I try to take the Work Axis from a Part, that is placed in the Assembly,

but Inventor does not generate the Pattern. If I set the Axis visible, or even rename it, it works. But the AddCircularPattern does not work.

 

 

' Part referenced in Obejct-Collection-Object

o_ObjectCollection (is defined)

 

' reference an Axis from Part, placed in Assembly

Dim o_CompOcc As ComponentOccurrence
o_CompOcc = o_AssyDoc.ComponentDefinition.Occurrences.Item(4)
Dim o_PartDoc As PartDocument = o_CompOcc.Definition.Document
Dim o_PartDef As PartComponentDefinition = o_PartDoc.ComponentDefinition

Dim o_WorkAxis As WorkAxis
o_WorkAxis = o_PartDef.WorkAxes.Item(3)
o_WorkAxis.Visible = True

 

' Add Circular Pattern with Axis from Part in the Assembly

Dim o_CircOccPatt As CircularOccurrencePattern
o_CircOccPatt = o_AssyDef.OccurrencePatterns.AddCircularPattern _
        (o_ObjectCollection, o_WorkAxis, True, "90 deg", 3)

 

 

I hope somebody can help me, because I really need this functionality.

 

Thank you very much,

abrink

Hello Mr. Varholik,

 

thank you very much, it works now the first time i tried it.

 

abrink100

Mentor
alewer
Posts: 189
Registered: ‎08-15-2006
Message 2 of 6 (243 Views)

Re: IV2012 API - AddCircularPattern doen't work with Axis from Part in Assembly

02-26-2013 01:31 PM in reply to: abrink100

I'd be happy to take a look if you upload a dataset (part+assembly) and code (simple complete subs) that show the behavior. Posting incomplete code snippets without models is stretching the limits of free advice.

 

For future API related questions, you'll probably have better luck with the customization forum: http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

Active Member
abrink100
Posts: 6
Registered: ‎02-26-2013
Message 3 of 6 (229 Views)

Re: IV2012 API - AddCircularPattern doen't work with Axis from Part in Assembly

02-27-2013 12:09 AM in reply to: alewer
Hello alewer, thanks for your help. I tried to put it correctly into two separate subs. The second Sub is the funcionality i need, but it doesn't work. The first one works. Atteched you will find the files. Thank you very much for help. Mr. Brinkmann Public Sub AddCircularPattern_Assembly_Axis(ByVal o_AssyDoc As Inventor.AssemblyDocument) ' reference Sheet-Part in Obejct-Collection-Object Dim o_CompOccs As ComponentOccurrences o_CompOccs = o_AssyDoc.ComponentDefinition.Occurrences ' ObjectCollection erstellen und das Element festlegen Dim o_ObjectCollection As Inventor.ObjectCollection o_ObjectCollection = o_Application.TransientObjects.CreateObjectCollection o_ObjectCollection.Clear() o_ObjectCollection.Add(o_CompOccs.ItemByName("Sheet")) ' reference an Axis of the Assembly Dim o_AssyDef As AssemblyComponentDefinition o_AssyDef = o_AssyDoc.ComponentDefinition Dim o_WorkAxis As WorkAxis o_WorkAxis = o_AssyDef.WorkAxes(1) ' X-Axis in Origin-Dir in Assembly ' Add Circular Pattern with Axis from Assembly Dim o_CircOccPatt As CircularOccurrencePattern o_CircOccPatt = o_AssyDef.OccurrencePatterns.AddCircularPattern _ (o_ObjectCollection, o_WorkAxis, True, "90 deg", 3) End Sub Public Sub AddCircularPattern_Part_Axis(ByVal o_AssyDoc As Inventor.AssemblyDocument) ' reference Sheet-Part in Obejct-Collection-Object Dim o_CompOccs As ComponentOccurrences o_CompOccs = o_AssyDoc.ComponentDefinition.Occurrences ' ObjectCollection erstellen und das Element festlegen Dim o_ObjectCollection As Inventor.ObjectCollection o_ObjectCollection = o_Application.TransientObjects.CreateObjectCollection o_ObjectCollection.Clear() o_ObjectCollection.Add(o_CompOccs.ItemByName("Sheet")) ' reference an Axis from Pipe-Part, placed in Assembly Dim o_CompOcc As ComponentOccurrence o_CompOcc = o_AssyDoc.ComponentDefinition.Occurrences.ItemByName("Pipe") Dim o_PartDoc As PartDocument = o_CompOcc.Definition.Document Dim o_PartDef As PartComponentDefinition = o_PartDoc.ComponentDefinition Dim o_WorkAxis As WorkAxis o_WorkAxis = o_PartDef.WorkAxes.Item(3) ' Z-Axis of Pipe-Part o_WorkAxis.Visible = True ' Add Circular Pattern with Axis from Assembly Dim o_AssyDef As AssemblyComponentDefinition o_AssyDef = o_AssyDoc.ComponentDefinition Dim o_CircOccPatt As CircularOccurrencePattern o_CircOccPatt = o_AssyDef.OccurrencePatterns.AddCircularPattern _ (o_ObjectCollection, o_WorkAxis, True, "90 deg", 3) End Sub
Contributor
JanVarholik
Posts: 20
Registered: ‎09-08-2011
Message 4 of 6 (221 Views)

Re: IV2012 API - AddCircularPattern doen't work with Axis from Part in Assembly

02-27-2013 02:43 AM in reply to: abrink100

Abrink100,

 

Could you also attach the dataset? (part and assembly files)

 

Thanks,

Jan

Contributor
JanVarholik
Posts: 20
Registered: ‎09-08-2011
Message 5 of 6 (206 Views)

Re: IV2012 API - AddCircularPattern doen't work with Axis from Part in Assembly

02-27-2013 05:19 AM in reply to: abrink100

I looked into this one closer and what you need to do is create a proxy object for the workaxis. The proxy object then can be passed as in input argument to AddCircularPattern(). What your code does is that it directly retrieves the axis from the part document, but we need to know which occurrence has been used...

 

Try to change your script to something like this:

 

Public Sub AddCircularPattern_Part_Axis()

    Dim o_AssyDoc As Inventor.AssemblyDocument
   Set o_AssyDoc = ThisApplication.ActiveDocument


   Dim o_AssyDef As AssemblyComponentDefinition
   Set o_AssyDef = o_AssyDoc.ComponentDefinition

   Dim o_CompOccs As ComponentOccurrences
   Set o_CompOccs = o_AssyDef.Occurrences

   Dim o_ObjectCollection As Inventor.ObjectCollection
   Set o_ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

   o_ObjectCollection.Clear
   o_ObjectCollection.Add o_CompOccs.Item(1)

   Dim o_CompOcc As ComponentOccurrence
   Set o_CompOcc = o_AssyDef.Occurrences.Item(1)

   Dim o_PartDef As PartComponentDefinition
   Set o_PartDef = o_CompOcc.Definition

   Dim o_WorkAxis As WorkAxis
   Set o_WorkAxis = o_PartDef.WorkAxes.Item(3)

   Dim o_PWorkAxis As WorkAxisProxy
   Call o_CompOcc.CreateGeometryProxy(o_WorkAxis, o_PWorkAxis)

   Dim o_CircOccPatt As CircularOccurrencePattern
   Set o_CircOccPatt = o_AssyDef.OccurrencePatterns.AddCircularPattern(o_ObjectCollection, o_PWorkAxis, True, "90 deg", 3)
End Sub

Active Member
abrink100
Posts: 6
Registered: ‎02-26-2013
Message 6 of 6 (194 Views)

Re: IV2012 API - AddCircularPattern doen't work with Axis from Part in Assembly

02-27-2013 05:47 AM in reply to: JanVarholik

Hello Mr. Varholik,

 

thank you very much, it works now the first time i tried it.

 

abrink100

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!