Get Origin (Center Point, xAxis etc.) from a ComponentOccurrence in Assembly

Get Origin (Center Point, xAxis etc.) from a ComponentOccurrence in Assembly

Robert.Egel7SPMT
Explorer Explorer
1,739 Views
8 Replies
Message 1 of 9

Get Origin (Center Point, xAxis etc.) from a ComponentOccurrence in Assembly

Robert.Egel7SPMT
Explorer
Explorer

Hello together,

 

currently I'm trying to import .stp-Files into an assembly which is working fine. But I want to set constraints, e.g. between the center points of each part. But after a big search, I cannot find the attribute which describes the axis' or center point of a part.

How can I access this attribute? When it opens in Inventor Assembly, it is clearly visible.

 

...

module1 = oAssyComDef.Occurrences.Add(name, oPosMatrix);

...

 

RobertEgel7SPMT_0-1669130923010.png

 

Greetings and Thank You!

 

0 Likes
1,740 Views
8 Replies
Replies (8)
Message 2 of 9

Zach.Stauffer
Advocate
Advocate

The origin is made up of 3 WorkPlanes, 3 WorkAxis, and 1 WorkPoints that are stored with other work features. For the axes you can access them by name, like this:

 

 

Dim xAxis As Inventor.WorkAxis = occurrence.Definition.WorkAxes.Item("X Axis")

 

 

WorkPlanes and WorkPoints are accessed in a similar manner. I haven't needed to access the CenterPoint though, not sure if its name is "Center Point" or not.

0 Likes
Message 3 of 9

WCrihfield
Mentor
Mentor

Hi @Robert.Egel7SPMT.  Zach was on the right track, but the one keyword ("ComponentDefinition") in the path was a little off for working with a component (should have been just "Definition").  Here is an example of some iLogic code in an assembly.  It has examples of getting the origin point and X axis of the first component in the assembly.  But those can not be used directly in constraints that are created at the main assembly level directly.  You must use a proxy of those objects for things like constraints and measurements.  Take a look at this code.

 

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oADef.Occurrences
Dim oConsts As AssemblyConstraints = oADef.Constraints
Dim oOcc1 As ComponentOccurrence = oOccs.Item(1)
Dim oOcc1OriginPoint As WorkPoint = oOcc1.Definition.WorkPoints.Item(1)
Dim oOcc1XAsis As WorkAxis = oOcc1.Definition.WorkAxes.Item(1)
'those are in the context of that other model document's 3D space, not main assembly
'to get them in assembly, use this method, and you will get their 'proxy' version
Dim oOcc1OriginPointProxy As WorkPointProxy = Nothing
oOcc1.CreateGeometryProxy(oOcc1OriginPoint, oOcc1OriginPointProxy)
Dim oOcc1XAxisProxy As WorkAxisProxy = Nothing
oOcc1.CreateGeometryProxy(oOcc1XAsis, oOcc1XAxisProxy)
'now you can use these proxy object for your measurements and constraints in the main assembly

Edit:  To help explain a bit more...the first WorkPoint object in every model document (parts & assemblies) will be the one shown within its Origin folder, so it will be its Origin Point.  The first 3 WorkPlanes found in every model type document will be its 3 origin planes, in the same order as you see them, with the X-Axis being the first one.  The first 3 WorkAxis objects found in every model type document will be its origin axis objects, in the order you see them.  Those natural objects are defined within the 3D coordinate system of that document only though, so when you put the model into an assembly, as a component, all the geometry from that model that you see in the assembly is 'proxy' geometry, meaning it is like a translated copy of the original geometry, and the original objects are not actually there.  Those proxy versions are now within the 3D coordinate space of the assembly, where it can not be measured to/from or constrained to something else in the assembly.  The only geometry really native to an assembly are its origin work features, any new work features that you create directly within the main assembly, and any sketches you create directly within the main assembly.  Pretty much everything else is a proxy.

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 9

Zach.Stauffer
Advocate
Advocate

Thanks for the correction, I was copying off code that was reading these off a document instead of an occurrence. I've fixed the code above.

 

I find it interesting that you use the Item(1) method of accessing features. I think using Item("Feature Name") is much more readable and easier to comprehend, especially for someone who is new to iLogic.

0 Likes
Message 5 of 9

Robert.Egel7SPMT
Explorer
Explorer

Hello together,

 

thanks for the answers, currently I'm trying to implement it.

Nevertheless, I cannot find based on the occurrence Defintion.WorkAxes.

 

RobertEgel7SPMT_0-1669135527292.png

 

But I could find it based on AssyComDef.

 

RobertEgel7SPMT_1-1669135591228.png

 

Greetings!

0 Likes
Message 6 of 9

WCrihfield
Mentor
Mentor

The code we were showing is sort of taking a shortcut.  The Definition property of a ComponentOccurrence object is a generic ComponentDefinition object, which is the base class for the more specific types like PartComponentDefinition & AsssemblyComponentDefinition, but will represent one of these more specific types.  The generic ComponentDefinition object does not have work features, which is why that property is not recognized.  Our code will normally still work OK though when used in an iLogic rule.  However, it looks like you are trying to use it in C# coding, which I am not as familiar with.  That may be more strict, so you may have to check which more specific type of component definition it represents first, then use a variable of that more specific type to work with.  What I mean is you could check if ComponentOccurrence.DefinitionDocumentType to see if it represents a part or an assembly (or you could use TypeOf operator), then create a variable of type PartComponentDefinition if it is a part, and set ComponentOccurrence.Definition as its value.  Then work with that variable from that point to avoid those properties not being recognized.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 9

Zach.Stauffer
Advocate
Advocate

Yes in C# you have to be more concrete about what you are getting. Here are 2 functions I use to mate the different types. These are part of a larger class so the assemblyComponentDef has been located and stored at an earlier point.

 

private void MatePart(ComponentOccurrence occurrenceToMate)
		{
			//get mating occurrence planes and proxies
			PartComponentDefinition occurrenceDef = (PartComponentDefinition) occurrenceToMate.Definition;
			
			var occurrenceXYplane = occurrenceDef.WorkPlanes["XY Plane"];
			var occurrenceXZplane = occurrenceDef.WorkPlanes["XZ Plane"];
			var occurrenceYZplane = occurrenceDef.WorkPlanes["YZ Plane"];

			//create proxies
			occurrenceToMate.CreateGeometryProxy(occurrenceXYplane, out object xyPlaneProxy);
			occurrenceToMate.CreateGeometryProxy(occurrenceXZplane, out object xzPlaneProxy);
			occurrenceToMate.CreateGeometryProxy(occurrenceYZplane, out object yzPlaneProxy);

			//create mates
			assemblyComponentDef.Constraints.AddFlushConstraint(xyPlaneProxy, xyPlane, 0);
			assemblyComponentDef.Constraints.AddFlushConstraint(xzPlaneProxy, xzPlane,0);
			assemblyComponentDef.Constraints.AddFlushConstraint(yzPlaneProxy, yzPlane, 0);
		}

		private void MateAssembly(ComponentOccurrence occurrenceToMate)
		{
			//get mating occurrence planes and proxies
			AssemblyComponentDefinition occurrenceDef = (AssemblyComponentDefinition)occurrenceToMate.Definition;

			var occurrenceXYplane = occurrenceDef.WorkPlanes["XY Plane"];
			var occurrenceXZplane = occurrenceDef.WorkPlanes["XZ Plane"];
			var occurrenceYZplane = occurrenceDef.WorkPlanes["YZ Plane"];

			//create proxies
			occurrenceToMate.CreateGeometryProxy(occurrenceXYplane, out object xyPlaneProxy);
			occurrenceToMate.CreateGeometryProxy(occurrenceXZplane, out object xzPlaneProxy);
			occurrenceToMate.CreateGeometryProxy(occurrenceYZplane, out object yzPlaneProxy);

			//create mates
			assemblyComponentDef.Constraints.AddFlushConstraint(xyPlaneProxy, xyPlane, 0);
			assemblyComponentDef.Constraints.AddFlushConstraint(xzPlaneProxy, xzPlane, 0);
			assemblyComponentDef.Constraints.AddFlushConstraint(yzPlaneProxy, yzPlane, 0);
		}

 

Message 8 of 9

Robert.Egel7SPMT
Explorer
Explorer

Hello together,

 

thank you very much. I tried it right now and it did work! This is exactly what I needed!

 

Greetings, have all a nice weekend!

0 Likes
Message 9 of 9

danielvdeleito
Contributor
Contributor

the 1st WorkPoint is an assembly and part is the Origin Point, so this is the simplest way:

	Dim oOriginPoint As Object
	oOriginPoint = oCompDef.WorkPoints.Item(1)
0 Likes