Hole Feature Error at CreateSketchPlacementDefinition?

Hole Feature Error at CreateSketchPlacementDefinition?

danmorick
Enthusiast Enthusiast
524 Views
3 Replies
Message 1 of 4

Hole Feature Error at CreateSketchPlacementDefinition?

danmorick
Enthusiast
Enthusiast

Here's what I have.  It adds a sketch in the flat pattern, projects the ends of the bend lines, and adds a points to the ends of each.

 

SyntaxEditor Code Snippet

Sub Main()

If ThisApplication.ActiveDocument.Subtype <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'not sheet metal document
Exit Sub
End If

Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oSMDef As ComponentDefinition = oPartDoc.ComponentDefinition
Dim oFeatures As SheetMetalFeatures = oSMDef.Features

Dim oFlat As FlatPattern = oSMDef.FlatPattern
Dim oEdge As Edge
Dim oEdges As Edges
Dim oEnt1 As SketchEntity
Dim oMdPt1 As SketchPoint
Dim oMdPt2 As SketchPoint
Dim oHoles As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oHoleDef As SketchHolePlacementDefinition
Dim oBendMarks As HoleFeature
Dim oSketch As PlanarSketch

'enter flat pattern and add sketch
oFlat.Edit
System.Threading.Thread.CurrentThread.Sleep(100)
oSketch = oFlat.Sketches.Add(oFlat.TopFace, False)
System.Threading.Thread.CurrentThread.Sleep(100)

oSketch.Edit

'get all bend lines, both up and down
oEdges = oFlat.GetEdgesOfType(64005, True)
For Each oEdge In oEdges
oEnt1 = oSketch.AddByProjectingEntity(oEdge)
oMdPt1 = oSketch.SketchPoints.Add(oEnt1.StartSketchPoint.Geometry, True)
oMdPt1.Merge(oEnt1.StartSketchPoint)
oMdPt2 = oSketch.SketchPoints.Add(oEnt1.EndSketchPoint.Geometry, True)
oMdPt2.Merge(oEnt1.EndSketchPoint)
oHoles.Add(oMdPt1)
oHoles.Add(oMdPt2)
Next

oEdges = oFlat.GetEdgesOfType(64004, True)
For Each oEdge In oEdges
oEnt1 = oSketch.AddByProjectingEntity(oEdge)
oMdPt1 = oSketch.SketchPoints.Add(oEnt1.StartSketchPoint.Geometry, True)
oMdPt1.Merge(oEnt1.StartSketchPoint)
oMdPt2 = oSketch.SketchPoints.Add(oEnt1.EndSketchPoint.Geometry, True)
oMdPt2.Merge(oEnt1.EndSketchPoint)
oHoles.Add(oMdPt1)
oHoles.Add(oMdPt2)
Next

oSketch.ExitEdit
oSketch.Name = "Bend Mark Sketch"


oHoleDef = oFlat.Features.HoleFeatures.CreateSketchPlacementDefinition(oHoles)'ERROR THIS LINE - PARAMETER INCORRECT
oBendMarks = oFlat.Features.HoleFeatures.AddDrilledByThroughAllExtent(oHoleDef, 0.254, kPositiveExtentDirection)

oBendMarks.Name = "Bend Marks"

End Sub

 

 

It consistently works all the way to the CreateSketchPlacementDefinition line; all sketch points are correctly placed, and the object collection count indicates that all sketch points have been added.  But in creating the PlacementDefinition it tells me the "parameter is incorrect".

 

If I click through the error, I am able to manually create the hole feature, and all the sketch points are recognized automatically.

 

Does anyone see what is wrong with my code?

0 Likes
525 Views
3 Replies
Replies (3)
Message 2 of 4

L.R20
Contributor
Contributor

Hi,

 

I borrowed your code and made it "work". I'm not a programmer so it may be not as elegant as your code. I think merging the points on the start and end points of the bendlines screws the holefeature up. If I skip this step (the point merge step), the rule somehow works.

 

See my code overhere:

https://forums.autodesk.com/t5/inventor-customization/prevent-rule-running-in-assembly/td-p/7060570

 

Kind regards,

Message 3 of 4

danmorick
Enthusiast
Enthusiast

Thanks for pointing that out!  I also got it to work when I suppressed those merge lines.  The issue then is that the points are not constrained to anything, so if the part changes the points might no longer mark the true bend line locations.  If I edit the sketch afterwards and make those points coincident where they are, the part updates perfectly.  It's strange that the merge method worked at one time for me and now it does not...

 

I'm glad you were able to use my code in some capacity.  I'm trying to figure out a different method of automatically locking those points onto the ends of the bend lines; I'll post my solution if I arrive at one.

0 Likes
Message 4 of 4

L.R20
Contributor
Contributor
I also had the problems with the unconstrained points. To solve this I used an Itrigger when geometry changes. So the rule behaves like this --> on geometry change --> remove hole markers ---> replace hole markers. Not very elegant as well, but it works. The code I posted in the URL I linked in my previous post to you has this function already built in. Owner2229 refined the whole rule with the same built in function.
0 Likes