Sketchlines3d delete unhealthy lines

Sketchlines3d delete unhealthy lines

Cadkunde.nl
Collaborator Collaborator
700 Views
5 Replies
Message 1 of 6

Sketchlines3d delete unhealthy lines

Cadkunde.nl
Collaborator
Collaborator

Hello Forum,

 

I have a code that makes a 'grid' that will be used to generate beams.

I can tell how many 'cubes' in the X, Y and Z direction and press build

Cadkundenl_1-1737643437283.png

And this is the result:

Cadkundenl_2-1737643574607.png

Workpoints and SketchLines3d between them.

 

Now im building an 'update button' that for example, you type in Zsize is 1

Then higher workpoints are deleted.

 

Cadkundenl_0-1737643325789.png

 

So the workpoints are deleted, and now i need to delete the sketchlines3d that were connected to these workpoints.

 

I can't find a way to delete the 'unhealthy' sketchlines3d

I guess it should be in sketchlines3d.constraints3d

But the items in there are generic 'objects' and i do not know how to find out which specific objects that could be.

 

Any help do determine the unhealthy sketchlines is greatly appreciated

 

 

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

WCrihfield
Mentor
Mentor

Hi @Cadkunde.nl.  As you iterate through the SketchConstraints3DEnumerator that you get from the SketchLine3D.Constraints3D, you can use a block of code that checks what each one is, then create a variable of that Type, then set that object as the variable's value, then use that variable.  In a situation like this, trying to use the ".Type" property to get the ObjectTypeEnum variation may be a bit too problematic / confusing, so I would recommend using the 'TypeOf' operator.  If you do use TypeOf operator, just keep in mind what the 'base object type' and the 'derived object types' are, and you should be just fine.  For instance, in this case GeometricConstraint3D will be the base type (and DimensionConstraint3D is the other base type), but then there are 23 sub types that are derived from the GeometricConstraint3D type (you can see them under 'Derived Classes' on the online help page).  But you are likely only looking for the CoincidentConstraint3D sub type, so no need to check for all sub types.

 

On the other hand, you could start from the Sketch3D.GeometricConstraints3D property.  You may be able to check if CoincidentConstraint3D.ConnectedEntity 'Is Nothing' for this task.  If that is true, then you can check the CoincidentConstraint3D.EntityOne &/or CoincidentConstraint3D.EntityTwo property values, to figure out what to delete, if possible.  May have to include some error handling / avoidance though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

Cadkunde.nl
Collaborator
Collaborator

Thanks,


I had this working at the end of the day:

For i = oLines.Count To 1 Step -1
Dim boolDelete As Boolean = False
For j = oLines(i).Constraints3D.Count To 1 Step -1
If oLines(i).Constraints3D.Item(j).Type = "83942144" Then
Dim oCon As CoincidentConstraint3D = oLines(i).Constraints3D.Item(j)
Try
If oCon.ConnectedEntity = Nothing Then
boolDelete = True
End If
Catch
End Try
End If
Next
If boolDelete = True Then oLines(i).Delete()
Next

 

But this also deletes any line an engineer would set, that is not from workpoint to workpoint.

I could first go to workpoints and 'mark them for deletion'

Then delete lines first that have are connected to a workpoint with a tag for deletion, before actually deleting the workpoints.

 

But that feels 2nd rate solution.

 

Inventor recognizes something is broken, since it connections are purple.

And I wonder if there is a boolean or something with reference missing or such

 

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

I don't use 3D sketches very often, and don't create them entirely by code at all, so some of this behavior is new to me also.

As a local test, I created a new part document, created a new 3D sketch in it, and created 4 sketch Points in it.  Then exited that sketch, and created 4 WorkPoints at those 4 sketch points.  Then turned visibility of first 3D sketch off.  Then created new 3D sketch, and created a total of 3 lines in it, each connecting between 2 of the WorkPoints.  Then I created 2 internal iLogic rules.  One for 'inspection' purposes, which iterates through all geometric constraints in that last 3D sketch, and reports all the accessible details of those constraints (constraint TypeName & Deletable status, and when coincident, the TypeName of (ConnectedEntity, EntityOne, & EntityTwo).  Other rule targets one line, and one of its coincident constraints, and uses disconnect method on the WorkPoint.  Disconnecting it did not delete the constraint, even though the UNDO list says that's what happened, and did not cause any issues/errors/problems, as if nothing happened.  Actually deleting one of the WorkPoints from the model browser tree does cause the issue/problem, so I did that, then 'inspected' the sketch again.  Two of the coincident constraints now do not have a 'ConnectedEntity', but they both still exist (same overall # of constraints), and both the EntityOne & EntityTwo both have same values (a SketchPoint3D & SketchLine3D).  For each WorkPoint that has two line end points connected to it, there are two coincident constraints, and only one coincident constraint for the WorkPoint at each end (6 total).

 

All those SketchPoint3D objects got created automatically by simply manually drawing those 3 lines between those 4 WorkPoints.  But the only constraints that were created are 6 coincident constraints that are all between those SketchPoint3D objects and the SketchLine3D objects, instead of directly between the WorkPoint objects and the SketchLine3D objects.  Since we can do this with, or without the WorkPoints, and we can also 'Disconnect' the WorkPoint from the Constraints by code, and they still seem OK, then there must be some sort of hidden constraint or association between the WorkPoint and the SketchPoint3D objects that got automatically created, since deleting the WorkPoint, without 'Disconnecting' them, causes issues/problems.

 

The SketchLine3D object, and the SketchPoint3D object both have a ConstraintStatus property which has a ConstraintStatusEnum type value, but that does not seem very relevant in this case, because it does not seem to contain a 'status' for something like 'broken/sick/driver lost'.  Since we can create both of those types of objects by specifying 'transient' mathematical inputs for their locations, instead of 'real / tangible' geometry objects (SketchPoints3D.Add & SketchLines3D.AddByTwoPoints), then it does not seem logical that they would be 'dependent' on any 'real' geometry objects.  I did notice that the SketchPoint3D object has the AttachedEntities propety, and the ConnectTo method, but it also has MoveBy method and MoveTo methods, which again only ask for transient mathematical inputs (but to warn about existing constraints preventing expected movement too).  A lot to think about.

Edit:  Below is the 'inspection' code I created, just for reference & further research efforts.  

Dim oInvApp As Inventor.Application = ThisApplication
Dim oActiveObj = oInvApp.ActiveEditObject
Dim oSketch3D As Sketch3D = Nothing
If TypeOf oActiveObj Is Sketch3D Then
	oSketch3D = oActiveObj
Else
	Try
		oSketch3D = oInvApp.CommandManager.Pick(SelectionFilterEnum.kSketch3DObjectFilter, "Select 3D Sketch To Inspect.")
	Catch oEx As Exception
		MsgBox(oEx.ToString)
		Return
	End Try
End If
If oSketch3D Is Nothing Then Return
Dim oGeomConsts As GeometricConstraints3D = oSketch3D.GeometricConstraints3D
If oGeomConsts.Count = 0 Then Return
Dim oReport As New System.Text.StringBuilder()
oReport.AppendLine("Sketch3D GeometricConstraints3D Report:")
oReport.AppendLine("GeometricConstraints3D.Count = " & oGeomConsts.Count)
For i As Integer = 1 To oGeomConsts.Count
	Dim oGeoCon As GeometricConstraint3D = oGeomConsts.Item(i)
	oReport.AppendLine()
	oReport.AppendLine("TypeName = " & TypeName(oGeoCon))
	oReport.AppendLine("Deletable = " & oGeoCon.Deletable)
	If TypeOf oGeoCon Is CoincidentConstraint3D Then
		Dim oCoinCon As CoincidentConstraint3D = oGeoCon
		oReport.AppendLine("ConnectedEntity TypeName = " & TypeName(oCoinCon.ConnectedEntity))
		oReport.AppendLine("EntityOne TypeName = " & TypeName(oCoinCon.EntityOne))
		oReport.AppendLine("EntityTwo TypeName = " & TypeName(oCoinCon.EntityTwo))
	End If
Next
Logger.Info(vbCrLf & oReport.ToString)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 6

basautomationservices
Advocate
Advocate

You could try serializing and saving the reference keys of the created lines and points to the part attributes when creating them and retrieving them when required.

Contact me for custom app development [email protected]. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


Message 6 of 6

Cadkunde.nl
Collaborator
Collaborator

Thanks all,

 

I'm working on a concept grid making feature, and see if this method is valid for engineering.

And it required to be able to update a grid that was made.

I keep it for now at 'marking' workpoints for deletion.

Then first delete any line attached to one, then delete the actual workpoint.

 

Once this concept is approved, we probably store creation data in an XML, a user parameter, or in attributes as Bas mentions.

 

As Crihfield mentions. ConnectedEntity of a line is empty when deleting the workpoint.
There is no 'link reference' that you sometimes find in other objects

EntityOne and EntityTwo can not be workpoints as objects.

So if there is a boolean, i would expect it here:

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-CoincidentConstraint3D

So how Inventor knows it and makes the endpoints purple, stays a mystery for me.

 

But ye, can't linger on it with so much work left to be done right 🙂

Thanks all, appreciated

 

 

0 Likes