iLogic extract position from element in a pattern

iLogic extract position from element in a pattern

MTheDesigner
Advocate Advocate
637 Views
6 Replies
Message 1 of 7

iLogic extract position from element in a pattern

MTheDesigner
Advocate
Advocate

I want to replace an item in a pattern. but in order to do that I need to get the position of the UCS for the element.

I tried using Constrints.AddUcsToUcs but when I suppress the element it no longer works.

 

How can I extract the position to give to another function?

0 Likes
638 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @MTheDesigner.  Are you talking about a pattern of components within an assembly?  If so, how do you want the information presented/formatted (a Matrix object, a Point object, an Array of Double containing the 3 coordinates, 3 Double type variables - one for each coordinate)?  How do you plan on using this 'position' data?  Are you aware the the ComponentOccurrence object has a property called Transformation (returns a Matrix) that contains all positional/rotational/orientation data of the component, and that is often used for placing/positioning components in assemblies?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

MTheDesigner
Advocate
Advocate
Hi @WCrihfield. I am trying to get a position so that I can replace the last subassembly with a different sub assembly. I am trying to place the new assembly with the components.add function. I have tried using a matrix to place it but the command requires a DocumantUnitMatrix, and I don't know how to convert between the two.
0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

Hi @MTheDesigner.  I think I may have an idea for you to explore for this situation.  I'm assuming you don't want to use the Component.Replace("Part1:1", "C:\Temp\Part2.ipt", False) type snippet for some reason, so I thought of a way to extract the regular Matrix from the existing component first.  Then gets its data to an array.  Then convert its data from database units to document units (if different units).  Then create a new DocumentUnitsMatrix object using the converted data from the original.  Then use your Components.Add() snippet with that.

You can test with this a try if you want.  You will obviously have to change component names, file names, and such first.

Dim oOccName As String = "Asm1:1"
Dim oFile As String = "C:\Temp\Asm2.iam"
Dim oExistingOccurrence As ComponentArgument = New ComponentArgument(oOccName)
Dim oPosition As Matrix = oExistingOccurrence.Occurrence.Occurrence.Transformation
Dim oCells() As Double = {}
oPosition.GetMatrixData(oCells)
UOM = ThisDoc.Document.UnitsOfMeasure
If UOM.LengthUnits <> UnitsTypeEnum.kDatabaseLengthUnits Then
	For Each oCell In oCells
		oCell = UOM.ConvertUnits(oCell, "cm", UOM.LengthUnits)
	Next
End If
Dim oNewPosition As DocumentUnitsMatrix = ThisDoc.Geometry.Matrix(oCells)
Components.Add(oOccName, oFile, oNewPosition)
'Component.Replace(oOccName, oFile, False)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

MTheDesigner
Advocate
Advocate

Hey @WCrihfield. Thanks for showing me how to convert into Documents unit matrix, I am sure that will be helpful in the future. However, I changed the strings as instructed but I get an error when I run it.
"Object reference not set to an instance of an object."

As for why i don't use Componet.Replace(name, file, false), Even though the last argument is false, when i try and replace it, it replaces every subassembly in the pattern. instead of just the named one

Dim oOccName As String = "CenterLanding:"&numberOfLandings
Dim oFile As String = "C:\muh path\AdaptableStairTower\LeftOffshoot.iam"
Dim oExistingOccurrence As ComponentArgument = New ComponentArgument(oOccName)
Dim oPosition As Matrix = oExistingOccurrence.Occurrence.Occurrence.Transformation
Dim oCells() As Double = {}
oPosition.GetMatrixData(oCells)
UOM = ThisDoc.Document.UnitsOfMeasure
If UOM.LengthUnits <> UnitsTypeEnum.kDatabaseLengthUnits Then
For Each oCell In oCells
oCell = UOM.ConvertUnits(oCell, "cm", UOM.LengthUnits)
Next
End If
Dim oNewPosition As DocumentUnitsMatrix = ThisDoc.Geometry.Matrix(oCells)
Components.Add("newThing", oFile, oNewPosition)
'Component.Replace(oOccName, oFile, False)

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

Hi @MTheDesigner.  I generally don't use those 'Components' or 'ComponentArgument' type iLogic only snippets, so I likely made a mistake in the part of the code where I'm getting the existing component.  I normally use the Inventor API route to get a component (AssemblyDocument.ComponentDefinition.Occurrences.ItemByName("ComponentName")).

Is this component that you are trying to replace the (or one of the) 'input' component in the component pattern, or is it one of the components that were created by the pattern?  If it is one of the input components, you pretty much can not avoid it effecting the rest of the pattern.  But if it is just one of the components that was created by the pattern, then we can make that one component independent, then replace it normally.  Here is a much simpler iLogic code for doing that.

 

oOcc = ThisAssembly.Document.ComponentDefinition.Occurrences.ItemByName("Part3:5")
If oOcc.IsPatternElement Then oOcc.PatternElement.Independent = True
oOcc.Replace("C:\Temp\Part4.ipt", False)
'oOcc.Replace2("C:\Temp\Part4.ipt", False, False, False)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

MTheDesigner
Advocate
Advocate

Hi @WCrihfeild,
Your replace solution works great for the last item in the pattern. The problem is that I need to also replace the first item in the pattern, my plan was to set the original instance to a reference and then use the extracted coordinates to place the new assembly in the same position.

Honestly trying to do this has been a struggle. I may need to find a new way to do things.

 

But thank you for the effort you have put into thinking about my problem. It is appreciated.

0 Likes