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: 

Why does enabling a constraint limit cause parent assemblies to be edited?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
cadull_rb
523 Views, 5 Replies

Why does enabling a constraint limit cause parent assemblies to be edited?

Parent assemblies of the one being edited in place report being changed when a constraint limit is enabled. To reproduce, open Assembly3 (attached) and edit Assembly1 as shown.

 

ConstraintLimit.png

 

Run the following code (also attached).

 

static void Main()
{
	Inventor.Application application = Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;

	ApplicationEvents events = application.ApplicationEvents;
	events.OnDocumentChange += OnDocumentChange;

	AssemblyComponentDefinition assembly = ((AssemblyDocument)application.ActiveEditDocument).ComponentDefinition;
	ComponentOccurrence component1 = assembly.Occurrences[1];
	ComponentOccurrence component2 = assembly.Occurrences[2];

	object workPlane1, workPlane2;
	component1.CreateGeometryProxy(((PartComponentDefinition)component1.Definition).WorkPlanes[1], out workPlane1);
	component2.CreateGeometryProxy(((PartComponentDefinition)component2.Definition).WorkPlanes[1], out workPlane2);
	MateConstraint constraint = assembly.Constraints.AddMateConstraint(workPlane1, workPlane2, 5);

	Console.WriteLine("Before enable constraint limit");
	constraint.ConstraintLimits.MinimumEnabled = true;
	Console.WriteLine("After enable constraint limit");
	constraint.ConstraintLimits.Minimum.Expression = "0";

	events.OnDocumentChange -= OnDocumentChange;
}

static void OnDocumentChange(_Document documentObject, EventTimingEnum beforeOrAfter, CommandTypesEnum reasonsForChange, NameValueMap context, out HandlingCodeEnum handlingCode)
{
	Console.Out.WriteLine("Document changed : {0} : {1} : {2}", reasonsForChange, beforeOrAfter, documentObject.DisplayName);
	handlingCode = HandlingCodeEnum.kEventNotHandled;
}

 

 The following is written to the console.

 

Document changed : kShapeEditCmdType : kBefore : Assembly1.iam
Document changed : kShapeEditCmdType : kAfter : Assembly1.iam
Before enable constraint limit
Document changed : kShapeEditCmdType : kBefore : Assembly1.iam
Document changed : kShapeEditCmdType : kBefore : Assembly2.iam
Document changed : kShapeEditCmdType : kBefore : Assembly3.iam
Document changed : kShapeEditCmdType : kAfter : Assembly1.iam
Document changed : kShapeEditCmdType : kAfter : Assembly2.iam
Document changed : kShapeEditCmdType : kAfter : Assembly3.iam
After enable constraint limit
Document changed : kShapeEditCmdType : kBefore : Assembly1.iam
Document changed : kShapeEditCmdType : kAfter : Assembly1.iam

I'm trying to defer updates to the parent assembly.

 

Regards,

cadull

5 REPLIES 5
Message 2 of 6
ekinsb
in reply to: cadull_rb

When you edit in place, the active document is still the top-level assembly.  I believe what's happening here is that you're editing the assembly and it's recomputing, which is also causing a recompute in all of the referencing document in order to react to the possible changes.


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

Thanks Brian,

 

It is interesting that if we remove the code that sets the limit value, Inventor indicates that the parent assemblies require an update, so the recompute is not a complete update. This led me to inspect the RequiresUpdate property of the document during the event processing and it appears to be suitable in filtering out changes that will require a subsequent update.

 

Regards,

cadull

Message 4 of 6
adam.nagy
in reply to: cadull_rb

Hi Cadull,

 

Has Brian answered your questions or you need more help?

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 5 of 6
cadull_rb
in reply to: adam.nagy

Hi Adam,

 

My question has been resolved in that I can determine when I don't need to update in response to the change notification. However, I still don't see why it should behave this way. It does this even if we insert an ActiveDocument.Update between the constraint creation and enabling the limit. I would expect it to behave in the same way as adding the constraint.

 

Regards,

cadull

Message 6 of 6
ekinsb
in reply to: cadull_rb

I agree that this is not the behavior I would expect.  I would have expected a shape edit notification from the upper levels assembly documents when the constraint was placed too since that could result in things moving within them.  If you've been able to resolve your problem I think I'll just leave it alone for now.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog

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

Post to forums  

Autodesk Design & Make Report