Create a sketch on a certain face in a part with iLogic

Create a sketch on a certain face in a part with iLogic

RajivAngoelal
Contributor Contributor
1,334 Views
6 Replies
Message 1 of 7

Create a sketch on a certain face in a part with iLogic

RajivAngoelal
Contributor
Contributor

Hello guys,

 

I want to make a code that "detects" a named face and create a sketch on that face.

I have a code, but i have to click the face to create a sketch.

 

The code:

oAssDoc = ThisApplication.ActiveDocument
oAssDef = oAssDoc.ComponentDefinition
Dim oFace As Face
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a Face ")
'make sure it is a planar face
If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then

oPlanarSurface = oFace.Geometry

'add a sketch
oSketch = oAssDef.Sketches.Add(oFace)

'trying to choose an appropriate point
'assume this planar face has one edge loop only
oEdgeLoop = oFace.EdgeLoops(1)

oMinPt = oEdgeLoop.RangeBox.MinPoint
oMaxPt = oEdgeLoop.RangeBox.MaxPoint

CenterPt = ThisApplication.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)

Else

End If

Is it possible to detect the ‘face0’ in the named geometry(without extra clicking) and create a sketch on that face?

Face0.jpg

Help is much appreciated 🙂

0 Likes
Accepted solutions (1)
1,335 Views
6 Replies
Replies (6)
Message 2 of 7

JelteDeJong
Mentor
Mentor

did you see this post about getting a named face?

https://forums.autodesk.com/t5/inventor-customization/where-is-new-feature-face-name-in-inventor-201... 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 7

RajivAngoelal
Contributor
Contributor

Dear JelteDeJong,

 

Yes i have seen the post, but the post had nothing to do with my preferred request.

i would like to create a sketch on a particular face. The name of the face does not matter.

 

 

0 Likes
Message 4 of 7

JelteDeJong
Mentor
Mentor
Accepted solution

I cant test this for you but you could try the following.

 

oAssDoc = ThisApplication.ActiveDocument
oAssDef = oAssDoc.ComponentDefinition
Dim oFace As Face
if (iLogicVb.Automation.NameExists("face0"))
	iLogicVb.Automation.FindEntity("face0")
else
	oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a Face ")
end if

'make sure it is a planar face
If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then

oPlanarSurface = oFace.Geometry

'add a sketch
oSketch = oAssDef.Sketches.Add(oFace)

'trying to choose an appropriate point
'assume this planar face has one edge loop only
oEdgeLoop = oFace.EdgeLoops(1)

oMinPt = oEdgeLoop.RangeBox.MinPoint
oMaxPt = oEdgeLoop.RangeBox.MaxPoint

CenterPt = ThisApplication.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)

Else

End If

(i got the idea from https://forums.autodesk.com/t5/inventor-customization/where-is-new-feature-face-name-in-inventor-201... )

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 7

RajivAngoelal
Contributor
Contributor

Thank you very much. it works :). 

 

i made the code a little bit smaller

 

On Error Resume Next

oDoc = ThisApplication.ActiveDocument
oDef = oDoc.ComponentDefinition

Dim partDoc As PartDocument = ThisDoc.Document
Dim namedEntities = iLogicVb.Automation.GetNamedEntities(partDoc)

Dim oFace As Face
oFace = namedEntities.FindEntity("Face0")
oSketch = oDef.Sketches.Add(oFace)
oSketch.name = "Face0"

Message 6 of 7

sam
Advocate
Advocate

@JelteDeJong wrote:

I cant test this for you but you could try the following.

 

oAssDoc = ThisApplication.ActiveDocument
oAssDef = oAssDoc.ComponentDefinition
Dim oFace As Face
if (iLogicVb.Automation.NameExists("face0"))
	iLogicVb.Automation.FindEntity("face0")
else
	oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a Face ")
end if

'make sure it is a planar face
If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then

oPlanarSurface = oFace.Geometry

'add a sketch
oSketch = oAssDef.Sketches.Add(oFace)

'trying to choose an appropriate point
'assume this planar face has one edge loop only
oEdgeLoop = oFace.EdgeLoops(1)

oMinPt = oEdgeLoop.RangeBox.MinPoint
oMaxPt = oEdgeLoop.RangeBox.MaxPoint

CenterPt = ThisApplication.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)

Else

End If

(i got the idea from https://forums.autodesk.com/t5/inventor-customization/where-is-new-feature-face-name-in-inventor-201... )

 


Hi, 
this might be dumb question but I am trying to use this as iLogic rule and it gives errors:

 

Error on Line 4 : 'NameExists' is not a member of 'Autodesk.iLogic.Interfaces.IiLogicAutomation'.
Error on Line 5 : 'FindEntity' is not a member of 'Autodesk.iLogic.Interfaces.IiLogicAutomation'.

 

Can you please explain why is this error coming up? is the rule meant to be used only in VBA or VB.NET?

 

Best regards, 

Sam

0 Likes
Message 7 of 7

sam
Advocate
Advocate

@RajivAngoelal wrote:

Thank you very much. it works :). 

 

i made the code a little bit smaller

 

On Error Resume Next

oDoc = ThisApplication.ActiveDocument
oDef = oDoc.ComponentDefinition

Dim partDoc As PartDocument = ThisDoc.Document
Dim namedEntities = iLogicVb.Automation.GetNamedEntities(partDoc)

Dim oFace As Face
oFace = namedEntities.FindEntity("Face0")
oSketch = oDef.Sketches.Add(oFace)
oSketch.name = "Face0"


This is working brilliantly as I thought. Thank you so much.