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: 

How to I reference a specific componentoccurence within an assembly to then reference the workplanes within that component occurence

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
j3scat
252 Views, 5 Replies

How to I reference a specific componentoccurence within an assembly to then reference the workplanes within that component occurence

I am unsuccessful in my attempt to create a component mate constraint between an assembly workplane and a part workplane from a second assembly, where both are inserted in a 'Master Assembly', (MA)

 

I have an assembly that I create reference workplanes, driven from an .xlsx file. (lets call this my 'Reference Assembly', RA). I am trying to create a rule that allows me to place an assembly and the rule automatically creates mate/flush constraints with this 'New Assembly'(NA). My rule works when I try to create a mate between planes located within the RA and the NA.  I can not figure out how to create a component mate between a plane located within a .ipt in my 'New Assembly' and a plane located inside my RA.

 

I have a subroutine to loop through my NA to locate the required workplane

FindSubPlane(NA.Definition.Document, SrchWPlane, "PlaneName"

Where NA references my freshly inserted assembly from a FileDialog

Dim NA As ComponentOccurrence
Dim aDoc As AssemblyDocument = ThisApplication.ActiveEditDocument Dim acomDef As AssemblyComponentDefinition = aDoc.ComponentDefinition

NA = acomDef.Occurrences.Add(File, InMatrix)
NA.Grounded = False

 

My subroutine is as follows;

Sub FindSubPlane(aDoc As AssemblyDocument, ByRef PPlane As WorkPlane, PName As String)
'^^^^ I have also tried defining PPlane As WorkPlaneProxy Dim acomDef As ComponentDefinition = aDoc.ComponentDefinition Dim aOcc As ComponentOccurrences = acomDef.Occurrences Dim MasterP As String ' MasterP is a parameter inside my .iam file that indicates the Key .ipt within Try MasterP = Parameter(aDoc.DisplayName, "MasterP") Catch MasterP = "" End Try
For Each GrOcc As Inventor.ComponentOccurrence In aOcc If GrOcc.Name = MasterP Then For Each SrchPl As WorkPlane In GrOcc.Definition.WorkPlanes If SrchPl.Name = PName Then PPlane = SrchPl 'GrOcc.CreateGeometryProxy(SrchPl, PPlane) '^^^ the above line is what I used when I attempted to create the WorkPlaneProxy inside the subroutine Exit Sub End If Next End If Next End Sub

 The above routine seems to find the correct WorkPlane. (or create my WorkPlaneProxy if that is what I was attempting)

 

If I simply pass back the WorkPlane, I fail at the following;

NA.CreateGeometryProxy(SrchWPlane, ProxSrchWPlane)

If I return the WorkPlaneProxy, I fail at the following;

acomDef.Constraints.AddFlushConstraint(ProxSrchWPlane, RAProxWPlane, 0)

 

The above .AddFlush or .AddMateConstraint works fine, If the ProxyPlanes are from the ReferenceAssembly and the NewAssembly.  I fails as soon as the ProxyPlane is from an .ipt within the NA.

 

What am I missing/doing wrong?

5 REPLIES 5
Message 2 of 6
A.Acheson
in reply to: j3scat

I think your just missing the declaration of a workplaneproxy in this line

'GrOcc.CreateGeometryProxy(SrchPl, PPlane)

This should be

 

Dim PPlaneProxy as WorkPlaneProxy
GrOcc.CreateGeometryProxy(SrchPl, PPlaneProxy)

 Now use the proxy part plane in the main assembly function. No need for anymore proxies, I think!!. These always trip me up so hopefully I have it right. 

 

Here is a vba sample for guidance

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 6
j3scat
in reply to: A.Acheson

I appreciate the reply, but I think it doesn't fix my issue, due to missing information from my end.

(When I typed my forum post, for some reason when I hit submit, there was an error and my entire post was lost, the post you read, was my second attempt and I was tired. I left out some info)

 

When I try to create the workplaneproxy in my subroutine, my sub header would be:

Sub FindSubPlane(aDoc As AssemblyDocument, ByRef PPlane As WorkPlaneProxy, PName As String)

I would also change the ByRef object type in my Main routine to be a Proxy plane

FindSubPlane(NA.Definition.Document, ProxSrchWPlane, "PlaneName")

 

I haven't completely worked through your VBA code sample yet, but using its nomenclature as a reference, I have a working subroutine that fairly closely replicates the situation of mating a WorkPlane from oOcc1 and oOcc2.  I think my issue is not knowing how to successfully mate a Workplane from oOcc1 and a sub part from oOcc2 (say oOcc2.oOcc2.1)

 

 

Message 4 of 6
WCrihfield
in reply to: j3scat

Hi @j3scat.  When working in assemblies, everything you see in that assembly that comes from a component is a proxy.  A proxy is basically a virtual copy of geometry that has been positioned & oriented within the 3D model space (or 'context') of the assembly).  Only things like work features or sketches that you create directly within the top level assembly itself will be 'normal/regular' objects, as expected.  So the origin planes of the main assembly file will be normal WorkPlanes, but the origin planes of a component will each be a WorkPlaneProxy within the context of a parent assembly.  When you need to create constraints or measure stuff between two components, both of those two geometries will need to be proxies.  If you are creating a constraint between the main/top assembly origin plane and a plane or face of a component, only the geometry of the component will need to be a proxy.

 

Proxies work on a 'per level' basis, so if the component you want to create a constraint to/from is not a top level component within the main assembly (within one or more levels of sub-assemblys), then the simples way to get that geometry will be with the Pick method (automatically returns the top level proxy, if component based).  If the Pick method is not an option, then you will need to start from the 'real' object within the base model file of the component, then get the component that represents that model within the sub-assembly and use its CreateGeometryProxy method to get a reference to the geometry's proxy that will be in the context of its parent assembly (in the context of the sub assembly).  Then get the component that represents the sub-assembly, and use its CreateGeometryProxy method to get the proxy that is within its parent assembly...and so on, until the proxy is within the context of the top level assembly.  It can be a lot of work to do this entirely by code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 6
WCrihfield
in reply to: j3scat

Also, if the purpose of your routine is to find and return a WorkPlaneProxy, then why not make it a Function instead of a Sub routine.  Functions are use to 'return' something, while a Sub is just to 'do' something, without returning anything.  If you change your routine to a Function, then leave out the 'input' WorkPlane or WorkPlaneProxy type object, leaving just the assembly document and plane name, then at the end of the 'definition' line, put "As WorkPlaneProxy" (without the quotes.  Then when you get the reference to the WorkPlaneProxy, use "Return oMyWorkplaneProxy" (without the quotes, and with the variable you were using).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6
j3scat
in reply to: WCrihfield

Why did I use a Sub instead of a function? Simply because I started with a Sub and just kept modifying that to make things work. Also, along the way, I suspected things worked like your advice directed, but I was trying the wrong approach and had multiple byRef references trying to return everything to the Main Subroutine. I switched my code to Functions. It required a little debugging, but cleaner in the end.

 

I simply uncommented my CreateGeometryProxy statements located in my Main from when I was simply returning the WorkPlane, not the WorkPlaneProxy. I then and added/switched the statements to use another layer of ProxyPlanes(and or Axes, as the case warranted)

 

Within my Main I switched my CreateGeometryProxy statement from

NA.CreateGeometryProxy(SrchPlane, ProxSrchPlane)

to use the now returned ProxySrchPlane

NA.CreateGeometryProxy(ProxSrchPlane, addProxSrchPlane)

  i was then able to create my constraints with

acomDef.Constraints.AddMateConstraint(addProxSrchPlane, RAProxWorkPlane, 0)

 

I greatly appreciate the help

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report