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: 

move part position and angle in assembly

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
GeorgK
4397 Views, 16 Replies

move part position and angle in assembly

Hello together,

 

how could I move a part to given position including the angles?

 

iProperties.png

 

To get the position and  angles:

 

http://adndevblog.typepad.com/manufacturing/2013/01/inventor-eulerian-angles-of-assembly-component.h...

 

Thank you

 

Georg

16 REPLIES 16
Message 2 of 17
Jef_E
in reply to: GeorgK

Well, you almost have the answer in full in front of you. Where you can GET the position you can also SET it. I never attempted to do this but the answer is surely in the page below. ( to use links please find the page in the API help file )

 

Spoiler
Matrix Object

Matrix Object

Description

A 4x4 Matrix object. For more information, see the Transient Geometry article in the overviews section.

Methods

Name Description
Copy Creates a copy of this Matrix object. The result is entirely independent and can be edited without affecting the original Matrix object.
GetCoordinateSystem Get the coordinate system that this matrix maps to from the standard coordinate system.
GetMatrixData Get the data defining this matrix.
Invert Invert this matrix.
IsEqualTo Compares this matrix for equality with the specified matrix.
PostMultiplyBy Method that post-multiplies this matrix by the specified matrix, setting this matrix to the result.
PreMultiplyBy Method that post-multiplies this matrix by the specified matrix, setting this matrix to the result.
PutMatrixData Method that sets the data defining this matrix.
SetCoordinateSystem Sets this matrix to be the matrix that maps from the standard coordinate system to the specified coordinate system.
SetToAlignCoordinateSystems Sets this matrix to be the matrix that maps from the 'from' coordinate system to the 'to' coordinate system.
SetToIdentity Sets this matrix to the identity matrix.
SetToRotateTo Sets to the matrix of rotation that would align the 'from' vector with the 'to' vector. The optional Axis argument may be used when the two vectors are perpendicular and in opposite directions to specify a specific solution, but is otherwise ignored.
SetToRotation Sets this matrix to the matrix of rotation by the specified angle, through the specified origin, around the specified axis.
SetTranslation Sets the translation portion of the matrix. If the optional ResetRotation flag is True, the rotation portion of the matrix is reset to identity.
TransformBy Method that sets this matrix to the result of this transformation followed by the specified transformation (a pre-multiplication of this matrix by the specified matrix).

Properties

Name Description
Cell Property that returns the cell defined by row/col.
Determinant Get the determinant of this matrix.
Translation Get the translation portion of the matrix.

Samples

Name Description
Adding iAssembly occurrences This sample demonstrates adding iAssembly occurrences to an assembly.
Adding iPart occurrences to an assembly This sample demonstrates adding iPart occurrences to an assembly.
Assembly Add Occurrence This sample demonstrates placing an assembly occurrence.
iMate Creation During Occurrence Placement This sample demonstrates creating multiple iMate results when adding an occurrence into an assembly. This uses the AddUsingiMate method which is the equivalent of using the Place Component command and checking the Use iMate check box on the dialog.
Demote occurence This sample demonstrates how to demote a top level occurrence in an assembly into a new sub-assembly occurrence.
SurfaceBody Copy This sample demonstrates copying a surface body from one part to another. This is equivalent to the Promote command, but the API is much more flexible. In order for the sample to be self-contained, it creates two parts on the fly that will be used to demonstrate copying a body from one part to another. When copying a body into a part, you provide the surface body and a matrix to define its position in the new part. This sample creates a matrix based on the position of these parts within an assembly.
Derived Parts and Assemblies This sample demonstrates the use of the API to create derived parts and assemblies.
Client Graphics - Line This sample demonstrates the creation of custom graphics using LineGraphics and LineStripGraphics. The same set of coordinate data is used for both types of graphics. Line graphics use two coordinates to define a line, and then the next two coordinates to define the next line, and so on through the defined coordinates. For the data provided, this results in gaps in the drawn curve. Line strips use the first two coordinates to define the first line and then the last point of the first line becomes the first point of the second line and the next coordinate is used as the end point of the second line. This results in the set of points being connected by a continuous set of lines, drawing a continuous curve. This sample also demonstrates two methods of defining the color for client graphics. In one case it uses an existing rendering style, and in the other, it explicitly defines a color and assigns it. To use the sample you need to have an assembly or part document open. The program has two behaviors: the first time it is run it will draw the graphics. The second time it is run it deletes the previously drawn graphics.
Create assembly occurrence with representations This sample demonstrates how to create an assembly occurrence by specifying various representations.
Assembly Move Occurrence This sample demonstrates moving a component occurrence. This sample performs a translate, but a rotate can also be performed since the transform is defined using a matrix.
UCS by transformation matrix This sample demonstrates the creation of a user coordinate system (UCS) by specifying a transformation matrix.

  



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 3 of 17
GeorgK
in reply to: Jef_E

 

' Have the occurrence that will be moved selected. 
        Dim occ As ComponentOccurrence
        occ = m_invApp.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select an occurrence.")


        ' Get the current grounded state of the selected occurrence.  
        Dim groundState As Boolean
        groundState = occ.Grounded

        ' Ground the occurrence. 
        occ.Grounded = True

        ' Get the current transformation matrix from the occurrence.
        Dim oTransform As Matrix
        oTransform = occ.Transformation

        ' Move the occurrence honoring any existing constraints.
        oTransform.SetTranslation(m_invApp.TransientGeometry.CreateVector(txtbox_X.Text / 10, txtbox_Y.Text / 10, txtbox_Z.Text / 10))
        occ.Transformation = oTransform

      
        ' Reset the grounded state of the occurrence back to 
        ' its original state. 
        occ.Grounded = groundState

But how could I rotate it around the 3 angels?

 

Georg

 

 

Message 4 of 17
Jef_E
in reply to: GeorgK

Eurmmm I don't know I bet with one of these 2 methods

 

Spoiler
Matrix.SetToRotation Method

Matrix.SetToRotation Method

Parent Object: Matrix

Description

Sets this matrix to the matrix of rotation by the specified angle, through the specified origin, around the specified axis.

Syntax

Matrix.SetToRotation( Angle As Double, Axis As Vector, Center As Point )

Parameters

Name Description
Angle Input Double that specifies the angle of rotation.
Axis Input Vector object.
Center Input Point object that specifies the origin.

Samples

Name Description
Assembly Add Occurrence This sample demonstrates placing an assembly occurrence.
UCS by transformation matrix This sample demonstrates the creation of a user coordinate system (UCS) by specifying a transformation matrix.

Version

Introduced in Inventor version 4

 

 

 

Spoiler
Matrix.SetToRotateTo Method

Matrix.SetToRotateTo Method

Parent Object: Matrix

Description

Sets to the matrix of rotation that would align the 'from' vector with the 'to' vector. The optional Axis argument may be used when the two vectors are perpendicular and in opposite directions to specify a specific solution, but is otherwise ignored.

Syntax

Matrix.SetToRotateTo( From As Vector, To As Vector, [Axis] As Vector )

Parameters

Name Description
From Input Vector object to align from.
To Input Vector object to align to.
Axis Input Vector object.

Remarks

Although the last argument is optional, a NULL (Nothing for VB users) must be passed in if the user wishes to ignore the argument.

Version

Introduced in Inventor version 4

 

Also should the grounded state be occ.grounded = false before the move? 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 5 of 17
ekinsb
in reply to: GeorgK

A 4x4 matrix is used in computer graphics to specify the position and orientation of objects in 3D space.  It's not something specific to Inventor but is common in most all CAD and computer graphics applications.  However, that doesn't mean that it's very intuitive to use.  I think the best way to understand it is to visualize the matrix as defining a coordinate system in 3D space and the occurrence will be positioned to align with that coordinate system.  Here's a link to a paper I presented at AU a few years ago that discusses this, along with a few other topics.  Hopefully it will help.

 

http://modthemachine.typepad.com/files/mathgeometry.pdf

 

-Brian


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 6 of 17
GeorgK
in reply to: ekinsb

Hello Brian,

 

thank you very much for the PDF. Do you have an example for the transformation and rotation arount all axis?

 

I could move the part and rotate it arounf one axis.

 

Georg

Message 7 of 17
ekinsb
in reply to: GeorgK

Sorry about the slow reply.  There's actually an example of rotating around multiple angles in the paper.  It's at the end of page 23.  The way it works is that you create a matrix that defines the rotation around either the x, y, or z axis and apply that rotation and then you can create another matrix that defines a rotation around one of the primary axes and then you apply that to the existing matrix to create a final matrix that defines both rotations.  

 

To tell you the truth, I don't know what the angles in the Occurrence Properties dialog even represent. What are those angles measuring?  Think about a part that has it's own x, y, and z axes and then you rotate that part 45 degrees around the z axis.  That's simple and everything makes sense.  But now rotate the part 30 degree around the x axis.  Where are the axes of the part pointing and how would you define that with three angle values?

 

If you can describe exactly what it is that you're trying to do I can probably put together some code that does that.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 8 of 17
GeorgK
in reply to: ekinsb

Hello Brian,

 

to rotate the parts is not the problem. I have an robot arm with 6 axis. From the last arm I would like to store the position including the pitch. After I move the robot I would like to drive the arm to this position (start position) including the stored pitch.

 

I hope it is clear now.

 

Thanks

 

Georg

Message 9 of 17
ekinsb
in reply to: GeorgK

I would store the position by storing the matrix.  Since the bottom row is always [0,0,0,1] you just need to store the other 12 values.  You can then use these values to construct a matrix and use it to set the position of the occurrence.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 10 of 17
GeorgK
in reply to: ekinsb

Hello Brian,

 

do you have a sample for the problem? Thank you

 

Georg

Message 11 of 17
ekinsb
in reply to: GeorgK

I'll put together a sample.  Where do you plane to store the last position?  In the assembly file or in an external document of some type?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 12 of 17
MechMachineMan
in reply to: GeorgK

Here is an example from one I did a while ago:

 

https://forums.autodesk.com/t5/inventor-customization/struggle-to-rotate-occurence-in-context-of-ass...


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 13 of 17
GeorgK
in reply to: ekinsb

Hello Brian,

 

the values could be stored in an external file.

 

Thank  you Georg

Message 14 of 17
adam.nagy
in reply to: GeorgK

Hi Georg,

 

Any particular reason for wanting to store the position in an external file?

You could just simply store it directly in the assembly as well:

http://modthemachine.typepad.com/my_weblog/2017/01/store-and-restore-occurrence-position.html

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 15 of 17
GeorgK
in reply to: adam.nagy

Hello Adam,

 

I have similar models where I would like to transfer the positions.

 

Thanks

 

Georg

Message 16 of 17
adam.nagy
in reply to: GeorgK

Hi Georg,

 

It should be relatively easy to transform the code to save the double values into a file instead.

You just have to figure out how you to identify the "similar" parts in similar models.

Maybe the name of the component is good enough?

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 17 of 17
GeorgK
in reply to: adam.nagy

Hello Adam,

 

the conversion works already. I use the clipboard and the filename.

 

Thanks for your help.

 

Georg

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report