Sketch Profiles methodology?

Sketch Profiles methodology?

J_Pfeifer_
Advocate Advocate
408 Views
5 Replies
Message 1 of 6

Sketch Profiles methodology?

J_Pfeifer_
Advocate
Advocate

Does anyone have a quick way to determine why a sketch may not be creating a profile to be passed into a feature?

 

I've had this happen several times, and short of rewriting the entire sketch objects I have no found a way to "solve" the problem. I also find the behavior of the sketch objects do not always match. This sketch is created identically to another that works perfectly. 

 

Does anyone have a programming methodology that works every time? Like do you guys use point2d objects to create the points to draw a line to, then draw from the end point of the previous line?

 

Or on the flip side, are you guys creating sketch objects and linking each line to them? So Line A gets drawn from a one irrelevant point to a sketch point object. Then the Line B Gets created from that sketch point object to another sketch point and so on?

 

This is what I mean when I say the "behavior". I've transferred the code between parts and next thing I know the profile refuses to be accepted on the new template part. 

 

The sketch is fully constrained, if I manually go to revolve the feature, it grabs the profile perfectly. However, trying to .addforsolid errors every time, with a logged check of the number of profiles in the sketch being 0. 

 

0 Likes
409 Views
5 Replies
Replies (5)
Message 2 of 6

Curtis_Waguespack
Consultant
Consultant

@J_Pfeifer_ , I don't do much of this kind of thing with automation, but when I have I typically add a line, and then find that line's end or start point and use that as the next line's start point. This will create inferred sketch constraints ( If I recall correctly) so that the profile is "water tight" and ready to extrude, etc.

see example:

 

Dim oCompDef As PartComponentDefinition
oCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oWorkPlane As WorkPlane
oWorkPlane = oCompDef.WorkPlanes.Item(2)

Dim oSketch As PlanarSketch
oSketch = oCompDef.Sketches.Add(oWorkPlane, False)


Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry

Dim oLine1 As SketchLine
oLine1 = oSketch.SketchLines.AddByTwoPoints(oTransGeom.CreatePoint2d(0, 0), oTransGeom.CreatePoint2d(4, 0))

firstPt = oLine1.StartSketchPoint
lastPt = oLine1.EndSketchPoint

Dim oLine2 As SketchLine
oLine2 = oSketch.SketchLines.AddByTwoPoints(lastPt, oTransGeom.CreatePoint2d(2, 3))

lastPt = oLine2.EndSketchPoint

Dim oLine3 As SketchLine
oLine3 = oSketch.SketchLines.AddByTwoPoints(lastPt, firstPt)

Dim oProfile As Profile
Try
	oProfile = oSketch.Profiles.AddForSolid
Catch
	MsgBox("Could not create profile")
End Try

 

EESignature

0 Likes
Message 3 of 6

J_Pfeifer_
Advocate
Advocate

Alright, I said to hell with the mess. Let me come up with some examples and situations. This was my result. 

 

First I attempted to create each element in the sketch as sketch points. Constrained all the sketch points to each other to make a square using alignments and dimensions. I was able to profile this object correctly. 

 

Then I took and created the same situation entirely with point2d objects to create the lines. Once the lines were created, I used themselves to apply the dimensions. This entirely failed and none of the lines had any associativity to each other. 

 

The final example, I used point2d objects to create the first line. From there I created new point2d objects for the ending of the next line. While the starting point for that line would be the previous Lines end point. This was able to profile and extrude properly. I refer to this as chasing the line. 

 

This has made me more confused and at a loss for attempting to find the problems within a broken sketch. The reason I say this is, each and every log within this part. Checking to see how many profiles are available in the sketches it would return 0. This means our only notification for what went wrong is "Incorrect parameter". There shouldn't be any other issues but I will take another look. Below is the attached empty part for others to investigate.

 

What I would do for some more error insights 😛

 

First attempt photo:

Sketchpoints.jpg

Second attempt:

Point2d.jpg

Third attempt:

ChasingLiens.jpg

0 Likes
Message 4 of 6

Curtis_Waguespack
Consultant
Consultant

@J_Pfeifer_ 

 

See this version of the "chasing" rule. It returns 1 profile... also I updated it to add sketch constraints to be fully constrained.

 

I'll take a look at the 2nd rule next, but I'd use the chasing method if I were doing this for myself ( for whatever that is worth, since I don't work creating sketches much 🙂

 

edit to add: I assume the 2nd version doesn't create a closed profile because there are no sketch constraints (inferred or explicit) placed on the line ends.

Hope that helps.

 

Sub main

	Dim oDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition

	Dim oTO As TransientObjects = ThisApplication.TransientObjects
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

	Dim Size As Integer = 10 * 2.54

	Dim CenterPoint As WorkPoint = oCompDef.WorkPoints.Item("Center Point")
	Dim BasePlane As WorkPlane = oCompDef.WorkPlanes.Item("XZ Plane")

	Dim oSketch As PlanarSketch = oCompDef.Sketches.Add(BasePlane)

	Dim oSketchPoint As SketchPoint = oSketch.AddByProjectingEntity(CenterPoint)

	'Use Point2d objects to setup the sketch, or first object. 
	Dim OriginPoint As Point2d = oTG.CreatePoint2d(0, 0)
	Dim BottomRightPoint As Point2d = oTG.CreatePoint2d(OriginPoint.X - Size, OriginPoint.Y)

	Dim Line1Bottom As SketchLine = oSketch.SketchLines.AddByTwoPoints(OriginPoint, BottomRightPoint)


	'Create the next point 
	Dim TopRightPoint As Point2d = oTG.CreatePoint2d(Line1Bottom.EndSketchPoint.Geometry.X, Line1Bottom.EndSketchPoint.Geometry.Y - Size)

	'Create the second line directly targetting the line object's sketch point. 
	Dim Line2Right As SketchLine = oSketch.SketchLines.AddByTwoPoints(Line1Bottom.EndSketchPoint, TopRightPoint)

	'New point
	Dim TopLeftPoint As Point2d = oTG.CreatePoint2d(Line2Right.EndSketchPoint.Geometry.X + Size, Line2Right.EndSketchPoint.Geometry.Y)

	'new line targetting pervious end
	Dim Line3Top As SketchLine = oSketch.SketchLines.AddByTwoPoints(Line2Right.EndSketchPoint, TopLeftPoint)

	'Then finally the last line can target the start point of the first line and the end point of the last line. 
	Dim Line4Left As SketchLine = oSketch.SketchLines.AddByTwoPoints(Line3Top.EndSketchPoint, Line1Bottom.StartSketchPoint)

	'Dimension all the lines

	Dim Line1Dim As DimensionConstraint = oSketch.DimensionConstraints.AddTwoPointDistance(Line1Bottom.StartSketchPoint, Line1Bottom.EndSketchPoint, kAlignedDim, oTG.CreatePoint2d(10, 10))

	Dim Line2Dim As DimensionConstraint = oSketch.DimensionConstraints.AddTwoPointDistance(Line2Right.StartSketchPoint, Line2Right.EndSketchPoint, kAlignedDim, oTG.CreatePoint2d(20, 20))


	oSketch.GeometricConstraints.AddCoincident(oSketchPoint, Line1Bottom.StartSketchPoint)
	oSketch.GeometricConstraints.AddHorizontal(Line1Bottom)
	oSketch.GeometricConstraints.AddVertical(Line2Right)
	oSketch.GeometricConstraints.AddEqualLength(Line1Bottom, Line3Top)
	oSketch.GeometricConstraints.AddEqualLength(Line2Right, Line4Left)

	'Profile, log and create example extrusion. 
	Dim SuperProfile As Profile = oSketch.Profiles.AddForSolid

	Logger.Info("Profiles within the chasing rule: " & oSketch.Profiles.Count)

	Dim ExtrusionExampleDef As ExtrudeDefinition = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(SuperProfile, kNewBodyOperation)
	ExtrusionExampleDef.SetDistanceExtent(Size, KnegativeExtentDirection)

	Dim ExtrusionExample As ExtrudeFeature = oCompDef.Features.ExtrudeFeatures.Add(ExtrusionExampleDef)

End Sub

 

EESignature

0 Likes
Message 5 of 6

J_Pfeifer_
Advocate
Advocate

My only concern with the Profiles.count was, in my head that would be the way to tell if the feature is erroring out due to a profile problem. I would expect that anytime it returns 0 profiles it would error on any feature. The strange part is, this is not the case from the two examples I provided. It seems the profiles.Count does not actually return the "profiles" that which the features are using. Granted, most inputs you're able to determine if they're okay or not. 

 

The reason this is significant is there is no way when working in this environment to determine whether the sketch is ready for a feature. Then the only two errors we get back from the feature are "unspecified" and "incorrect parameter" I have no recourse for fixing or identifying the problem. When I open the sketch, all lines are attached and dragging the sketch when not constrained reflects that all the lines are connected. Nor is there a a close loop method or property on the sketch itself. 

 

What only compounds my frustration is, if you were to simply click extrude, or revolve inside the UI of inventor. It immediately grabs the entire profile. So it clearly can, but also cannot see the profile. If the profile is supplied directly to a feature in Ilogic, it fails. If the profile is found and applied manually its perfectly fine. Neither a 1 or a 0 in the count return has any impact on that profile actually working within the feature. 

 

In my digging in the past, I've found a few threads going down this rabbit hole. Where some people made programs to sift through each line, comparing ends to starts and starts to ends. I mean we have Sketch.solve() that isn't even that clear as to what it does, it sounds like an odoc.update without updating the whole document. 

0 Likes
Message 6 of 6

Curtis_Waguespack
Consultant
Consultant

@J_Pfeifer_ , this example might or might not shed some light on the profiles:

 

Inventor 2025 Help | Sketch profile control | Autodesk

 

EESignature

0 Likes