Add sketch to part on parent assembly's workplane

Add sketch to part on parent assembly's workplane

FINET_Laurent
Advisor Advisor
246 Views
3 Replies
Message 1 of 4

Add sketch to part on parent assembly's workplane

FINET_Laurent
Advisor
Advisor

Hello folks,

 

I'm stuck on something. Say we have an assembly assembly.iam with a workplane workplane1Inside this assembly I have a part, part1.ipt. I would like to create a sketch inside this part1.ipt, using the workplane1 from the parent assembly.iam... by code.

 

You can achieve this manually by double-clicking the part inside the assembly, thus entering some sort of edit mode. Once the created sketch is made, the part become adaptative. I would like to reproduce that, but had no luck so far.

 

Has any one an idea ?

 

Thank you & kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Accepted solutions (2)
247 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @FINET_Laurent.  Situations like that can be a bit mind bending to approach from a code standpoint, but are often simpler than you might think, like in this case.  If that WorkPlane already exists in the main assembly, and the part is a top level component in that assembly, then all you would need to do is have a reference to the assembly level WorkPlane by setting it as the value of a variable, before entering into 'edit mode' then enter into edit mode, then create the sketch based on that assembly work plane, then draw something on it, then exit edit mode.  Below is a quickie example iLogic rule I just typed up for this task.  In this example the assembly work plane was named "Work Plane1", the part component was named "Center of Slot:1".  After you run the rule, there is now a new 'Adaptive' WorkPlane in your part, with a sketch on it.

	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Return
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oAsmWP1 As WorkPlane = oADef.WorkPlanes.Item("Work Plane1")
	Dim oOccs As ComponentOccurrences = oADef.Occurrences
	Dim oPlateOcc As ComponentOccurrence = oOccs.ItemByName("Center Of Slot:1")
	Dim oPlateDef As PartComponentDefinition = oPlateOcc.Definition
	oPlateOcc.Edit
	Dim oPlateSketch As PlanarSketch = oPlateDef.Sketches.Add(oAsmWP1, False)
	Dim oP2d As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0,0)
	Dim oSkCircle As SketchCircle = oPlateSketch.SketchCircles.AddByCenterRadius(oP2d, 3.0)
	oPlateOcc.ExitEdit(ExitTypeEnum.kExitToTop)

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)

Message 3 of 4

FINET_Laurent
Advisor
Advisor
Accepted solution

Hello @WCrihfield,

 

Funny enough, this is the same code I was using. The only thing I didn't do was creating some geometries inside the sketch. The code was then executed with no exceptions but also with no vivible results. Here with your code, the sketch is indeed created with the geometry. But inside the browser tree nothing happens (there is no sketch item) :

FINET_Laurent_0-1705995306999.png

 

I don't know why it is like this. When making the process with the mouse we get a different result. It creates some sort of intermediate adaptative workplane that guess whould humm..serve as reverse proxy I guess.

FINET_Laurent_2-1705996800715.png

I tried achieving this by code by adding a workplane inside the part using the reference with no result. The browser tree would be correct but no adapativity between the work two work plabnes.

 

SO I juste brute force it like an animal and use the command manager :

Dim assyDoc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument
Dim acd As Inventor.AssemblyComponentDefinition = assyDoc.ComponentDefinition

Dim refWp As Inventor.WorkPlane = acd.WorkPlanes.Item(4)

Dim targetOcc As Inventor.ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "")
targetOcc.Edit

assyDoc.SelectSet.Clear
assyDoc.SelectSet.Select(refWp)

ThisApplication.CommandManager.ControlDefinitions.Item("AppSketch2DWrapperCmd").Execute

targetOcc.ExitEdit(ExitTypeEnum.kExitToTop)

Dim pcd As Inventor.PartComponentDefinition = targetOcc.Definition
Dim sk As Inventor.PlanarSketch = pcd.Sketches.Item(1)

Dim p As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0,0)
Dim s As SketchCircle = sk.SketchCircles.AddByCenterRadius(p, 3)

 

I would have prefered your solution but I guess having a sketch that you can't turn back on once made invisible might be a problem. I also tried various things like rebuilds, close & open documents back. Nothing seems to do it. Just out of curiosity, is it the same in your app? If not, what version are you using?

 

Thanks for your help still.

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @FINET_Laurent.  After I saw your response today, I opened up my small test assembly again, got rid of that new sketch, and eliminated the 'Adaptive' statuses from everything, then took multiple screen shots of the assembly's model browser and assembly model area.  Then I ran that rule I posted above again.  Then I took some more screen shots of those same areas afterwards, to show what it did for me.

Before images:

WCrihfield_0-1706014613297.png 

WCrihfield_1-1706014630328.png

Then ran the rule.  Then below are images afterwards:

WCrihfield_2-1706014677483.png 

WCrihfield_3-1706014692967.png

Those two were in the assembly, and below were taken from within the plate part, after opening it, after the rule ran.

WCrihfield_4-1706014761270.png

WCrihfield_5-1706014773883.png

I am currently using 2024.0.1 (even though I requested we be updated to 2024.2 through our IT department about 2 months ago 🙄).

 

It does seem like I have done something similar to this at least once or twice before, but in a different, and more complicated way, but I have not had time to do a more thorough search through all my old stuff.  Did you notice that there is now a new Flush type assembly constraint, with zero offset, on the assembly WorkPlane afterwards?  And it knows which side has control over that WorkPlane, because the one in the assembly is still not Adaptive, but the new one that was created within the part is Adaptive (driven by the one in the assembly).  Maybe inspecting that new FlushConstraint will reveal something useful, but I have not gotten to that step yet.  Could inspect the definition type (WorkPlane.DefinitionType & WorkPlaneDefinitionEnum) of the new WorkPlane in the part too (WorkPlane.Definition), then dig further into how it was defined, but have not done that yet either.  Trying to keep up with work and multiple ongoing forum inquiries/projects at the same time is complicated to balance sometimes.

 

 

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes