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: 

Constraining Sketch Point or Work Plane to Assembly's Center of Gravity with iLogic

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
danielcLJDRZ
677 Views, 11 Replies

Constraining Sketch Point or Work Plane to Assembly's Center of Gravity with iLogic

I've been working on an assembly and I'm facing some difficulties. My objective is to constrain a component's sketch point or work plane to the assembly's center of gravity (CoG). Despite trying various methods, I haven't been successful.

I was wondering if this task could be accomplished using iLogic? I'm relatively new to iLogic, so any guidance on this would be incredibly helpful.

Here's what I've attempted so far:

  1. Determining the Center of Gravity: Using the "Center of Gravity" command, I can visualize the CoG of the assembly. However, utilizing this point directly for constraints has proven to be challenging.

  2. Reference Geometry Creation: I tried creating reference geometry (such as a work point or work plane) at the CoG. While I can create these references, constraining my component’s sketch point or work plane to these references hasn't yielded the desired results.

Is there a way to leverage iLogic to simplify this process? If so, a step-by-step explanation or any example codes would be immensely valuable.

11 REPLIES 11
Message 2 of 12

Could you share a component that needs to be constraint in the assembly, the assembly file is not needed in this case?

Could you also give me the sketchpoint you need to use?

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 3 of 12

I'm trying to constrain the sketch point center of the 6.010 rectangle to the CoG.

Message 4 of 12

Here you have a piece of code that created a UCS at the center of Gravity (Center Of Mass).

Herewith you can constraint the component....

Sub main
  
    Dim oDoc As AssemblyDocument = ThisAssembly.Document

    Dim oCompDef As AssemblyComponentDefinition
    oCompDef = oDoc.ComponentDefinition
	
    Dim acg As MassProperties = oCompDef.MassProperties
    Dim p As Point = acg.CenterOfMass

    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    Dim oMatrix As Matrix
    oMatrix = oTG.CreateMatrix

    Dim oTranslationMatrix As Matrix
    oTranslationMatrix = oTG.CreateMatrix
    Call oTranslationMatrix.SetTranslation(oTG.CreateVector(p.X, p.Y, p.Z))

    Call oMatrix.TransformBy(oTranslationMatrix)

    Dim oUCSDef As UserCoordinateSystemDefinition
    oUCSDef = oCompDef.UserCoordinateSystems.CreateDefinition

    oUCSDef.Transformation = oMatrix

    Dim oUCS As UserCoordinateSystem
    oUCS = oCompDef.UserCoordinateSystems.Add(oUCSDef)
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 5 of 12
danielcLJDRZ
in reply to: danielcLJDRZ

Thank you so much!!

Message 6 of 12

Appreciated...

Let me know if I can do something else for you.

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 7 of 12
danielcLJDRZ
in reply to: danielcLJDRZ

Is there a way to have the UCS update when the CoG changes?

Message 8 of 12

sure:

 

Sub main
    ' Create a new part document
    Dim oDoc As AssemblyDocument = ThisAssembly.Document

    Dim oCompDef As AssemblyComponentDefinition
    oCompDef = oDoc.ComponentDefinition
	
	Dim acg As MassProperties = oCompDef.MassProperties
	Dim p As Point = acg.CenterOfMass

    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    ' Create an identity matrix
    Dim oMatrix As Matrix
    oMatrix = oTG.CreateMatrix

    Dim oTranslationMatrix As Matrix
    oTranslationMatrix = oTG.CreateMatrix
    Call oTranslationMatrix.SetTranslation(oTG.CreateVector(p.X, p.Y, p.Z))

    Call oMatrix.TransformBy(oTranslationMatrix)

    ' Create an empty definition object
    Dim oUCSDef As UserCoordinateSystemDefinition
    oUCSDef = oCompDef.UserCoordinateSystems.CreateDefinition

    oUCSDef.Transformation = oMatrix

    Dim oUCS As UserCoordinateSystem
	
	Try
		
	oUCS = oCompDef.UserCoordinateSystems.Item("UCS_COG")
	oUCS.Transformation = oMatrix
	
	Catch
	oUCS = oCompDef.UserCoordinateSystems.Add(oUCSDef)
	oUCS.Name = "UCS_COG"	
		
End Try
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 9 of 12

I think now you are asking me, it is better to create a add-in for Inventor because you could use the Events better.

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 10 of 12

How do I create an add-in to achieve this update?

Message 11 of 12

Are you a bit familiar with Vb.net?

For now you can also add the rule to the save Event found in the Ilogic Event Triggers...

bradeneuropeArthur_1-1715977964749.png

 

bradeneuropeArthur_0-1715977920307.png

 

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 12 of 12

Hi Arthur,

 

I'm not very familiar with VB.NET. Could you please provide some guidance or resources on how to add the CG auto-update rule to the save event using the iLogic Event Triggers?

 

Thanks,

Dan

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

Post to forums  

Autodesk Design & Make Report