Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic underconstrained sketches

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
Curtis_Waguespack
2342 Views, 18 Replies

iLogic underconstrained sketches

I've created a rule to check for fully constrained sketches. The problem seems to be that projected geometry is not being recognized as fully constrained.

 

I was wondering if anyone would happen to know if this is a bug, or if I am just overlooking something. I've attached a simple part (Inventor 2010) containing the rule.

 

Thanks in advance,

Curtis
http://inventortrenches.blogspot.com

 

 

 

18 REPLIES 18
Message 2 of 19
MjDeck
in reply to: Curtis_Waguespack

Curtis,

This is a known issue (internal number 1011232).

Note that it's not saying that the sketch is underconstrained: it's saying that the status is unknown.  The ConstraintStatus property is ConstraintStatusEnum.kUnknownConstraintStatus.  It seems like it is not looking into the sketch in enough detail to get the actual constraint status.


Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 19
Curtis_Waguespack
in reply to: MjDeck

Thanks for looking into this Mike.

Message 4 of 19

Hi Curtis,

 

I realise it's been a while since you posted this but would you mind sharing the ilogic routine you created to do this?

 

Thanks,

 

Alex.

Message 5 of 19

Hi AlexF1980,

 

There is a rule in the part file that is attached to the first post of this thread that contains the code, you can use this to see the original issue. But here is the code as well (in case it helps someone find this in a search at some point in the future).

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

'kFullyConstrainedConstraintStatus = 51713 
'kUnderConstrainedConstraintStatus = 51714 
'kOverConstrainedConstraintStatus = 51715 
'kUnknownConstraintStatus = 51716 

'i for counter
Dim i As Long
i = 0

'iterate through each sketch in the part
Dim oSketch As PlanarSketch
For Each oSketch In oPartDoc.ComponentDefinition.Sketches

'check for sketches that are not Fully constrained
If oSketch.ConstraintStatus <> 51713  Then

'increment count by 1 for each undersconstrained sketch found
i = i + 1

'create a selection set
Dim oSS As SelectSet
oSS = ThisApplication.ActiveDocument.SelectSet
'make sure nothing is selected
oSS.Clear
'select the current sketch
oSS.Select(oSketch)

'find the sketch in the browser
Dim oControlDef As ControlDefinition
oControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppFindInBrowserCtxCmd")
oControlDef.Execute

'display message
MessageBox.show(oSketch.Name & " is not fully constrained." , _
"ilogic",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)

oSS.Clear
End If
Next oSketch

'display count message
if i = 1 then
MessageBox.show("A total of "&  i & " sketch is not fully constrained.", "ilogic", _
MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
else if i > 1 then
MessageBox.show("A total of "&  i & " sketches are not fully constrained.", "ilogic", _
MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
else if i < 1 then
'do nothing
end if

'--collapse all browser nodes back
'Set a reference to the top node of the active browser
Dim oTopNode As BrowserNode
oTopNode = oPartDoc.BrowserPanes.ActivePane.TopNode

Dim oNode As BrowserNode

For Each oNode In oTopNode.BrowserNodes
	' If the node is visible and expanded, collapse it.
	If oNode.Visible = True And oNode.Expanded = True Then
	oNode.Expanded = False
	End If
Next

 

Message 6 of 19

Hi Curtis,

 

Thanks for the code; I had overlooked the file you originally posted.

 

Do you know if the projected geometry issue was ever fixed? I am using Inventor 2013 so I would assume it *must* have been dealt with by now?

 

EDIT: Having just ran the code on an Inventor 2013 part file with upwards of 50 sketches, even those sketches that did have the "fully constrained" drawing pin symbol but had projected geometry in them were shown to be under constrained.

 

I'm going to take a wild stab in the dark and say that the issue hasn't been fixed yet. WTF!?

Message 7 of 19
AlexFielder
in reply to: AlexFielder

here are the results of my research this morning:

 

With a part file containing 3 sketches, one completely unconstrained, the 2nd using projected geometry from the first (so fully constrained for all intents & purposes) and a third sketch fully dimensioned and constrained about the centre point, it seems this issue is alive and well.

 

Here follows a VBA snippet I created with help from the Inventor "Programming Help" file which will show you exactly what I mean:

 

Public Sub MoveSketchObjects()
    ' Check to make sure a sketch is open.
    If Not TypeOf ThisApplication.ActiveEditObject Is Sketch Then
        MsgBox ("A sketch must be active.")
        Exit Sub
    End If

    ' Set a reference to the active sketch.
    Dim oSketch As Sketch
    Set oSketch = ThisApplication.ActiveEditObject
    
    Dim oSketchObjects As ObjectCollection
    Set oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection
    
    ' Get all entities in the sketch
    Dim oSketchEntity As SketchEntity
    For Each oSketchEntity In oSketch.SketchEntities
        If Not oSketchEntity.[_GeometryMoveableStatus] = kFixedGeometryMoveableStatus Then
            If Not oSketchEntity.ConstraintStatus = kFullyConstrainedConstraintStatus Then
                oSketchObjects.Add oSketchEntity
            End If
        End If
    Next
    
    If oSketchObjects.Count > 0 Then
        ' the sketch has unconstrained objects and is broken?
        MsgBox ("this sketch needs some constraints!")
    Else
        MsgBox ("Nothing to see here, move along!")
    End If
End Sub

 Oddly, even when I run this code in iLogic, it still presents that all three sketches need constraints added to them which isn't the case. What am I missing?

 

(Attached are my Inventor 2013 part file and the above code in iLogic format)

Message 8 of 19
MjDeck
in reply to: AlexFielder

Alex,

 It will work if you add the lines:
Imports Inventor.ConstraintStatusEnum
Imports Inventor.GeometryMoveableStatusEnum

at the top of the rule. These are required to get the values for kFixedGeometryMoveableStatus and kFullyConstrainedConstraintStatus.
 Whenever you copy VBA code that has an Inventor enum constant (starting with a k), search for the name in the Inventor help. That will give you the enum type name. Add that to the rule in an Imports statement.


Mike Deck
Software Developer
Autodesk, Inc.

Message 9 of 19
AlexFielder
in reply to: MjDeck

Thanks Mike, that makes perfect sense now that you have said it.

 

This sort of useful tip needs to be shouted from the rooftops as I am sure I am not the only who has fallen foul of it.

 

It surprises me that Inventor completely ignores that those two imports were missing from the ilogic code- are there plans for better debugging/error catching of iLogic code?

Message 10 of 19
MjDeck
in reply to: AlexFielder

By default, iLogic sets the VB option

Option Explicit Off

This allows you to use variables without declaring them. We did it this way for ease of use and VBA compatibility. But a downside is that you don't get an error message for Enum constants that are not found.
You will get the compiler error messages if you add
Option Explicit On

at the top of the rule.

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 11 of 19
bhanukiranss
in reply to: MjDeck

Hi...

 

Can you please help me .... I have also same problem of not getting projected geometry detected for identofying sketch status.

I want to write a program in VB not in ilogic....So can you please help me where i was getting wrong.

Below is my code...

Sub changeSketchname()
Dim ptDoc As PartDocument
Dim ptDocDef As PartComponentDefinition
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
MsgBox "please open a part document"
Exit Sub
End If
Set ptDoc = ThisApplication.ActiveDocument
Set ptDocDef = ptDoc.ComponentDefinition
Dim Sketches As PlanarSketch
Dim prefix As String
MsgBox "Total number of Sketches = " & ptDoc.ComponentDefinition.Sketches.Count
Dim i As Integer
For i = 1 To ptDoc.ComponentDefinition.Sketches.Count
If ptDoc.ComponentDefinition.Sketches.Item(i).ConstraintStatus = kFullyConstrainedConstraintStatus Then
MsgBox ("Sketch" & i & " is fully constrained")
Else
MsgBox ("Sketch" & i & "is not fully constrained")
End If
Next
End Sub

 

Tags (1)
Message 12 of 19
mark.solway
in reply to: MjDeck

Hi Mike,

 

I have added the code you have stated above

 

Imports Inventor.ConstraintStatusEnum
Imports Inventor.GeometryMoveableStatusEnum

 

but I am getting a Syntax error.

 

Do you know if this code is no longer compatible with Inventor 2014?

 

Your help is much appreciated.

 

Mark

Message 13 of 19
DRoam
in reply to: MjDeck


@MjDeck wrote:

This is a known issue (internal number 1011232). [...] It seems like it is not looking into the sketch in enough detail to get the actual constraint status.


Can this please be fixed? I'm trying to use the rule below to let me know if any sketches are underconstrained, but some sketches with projected geometry are returning "unknown", even if the sketch is fully constrained OR underconstrained.

 

Dim ruleName As String = "Find Underconstrained Sketches"

Dim partDoc As PartDocument = ThisDoc.Document

Dim badSketches As New List(Of String)

For Each sk As Sketch In partDoc.ComponentDefinition.Sketches
	If Not sk.ConstraintStatus = ConstraintStatusEnum.kFullyConstrainedConstraintStatus Then badSketches.Add(sk.Name & " (" & sk.ConstraintStatus.ToString & ")")
Next

If badSketches.Count > 0 Then
	MessageBox.Show("The following (" & badSketches.Count & ") sketches are not fully constrained: " & vbCr & vbCr & String.Join(vbCr, badSketches), ruleName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
	MessageBox.Show("All sketches are fully constrained!", ruleName, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

 

Message 14 of 19
MjDeck
in reply to: DRoam

@DRoam , can you post a part that shows the problem? Or steps to recreate?
The 1011232 issue had a test case with projected geometry, and it looks like that has been resolved in Inventor 2021 or earlier. You might be seeing something that is similar but not identical.


Mike Deck
Software Developer
Autodesk, Inc.

Message 15 of 19
R.Mabery
in reply to: MjDeck

@MjDeck  The attached part exhibits this behavior.  Sketch36 is reporting a sketch line and a sketch point that are underconstrained.  I'm looking at the oSketchEntity.ConstraintStatus.

 

 


Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
Message 16 of 19
MjDeck
in reply to: R.Mabery

@R.Mabery , can you share code that shows this problem? I don't see it in Inventor 2021.1 build 245. Here's the rule I'm using:

 

Option Explicit On
Dim partDoc As PartDocument = ThisDoc.Document
Dim compDef As PartComponentDefinition = partDoc.ComponentDefinition

For Each pSketch As PlanarSketch In compDef.Sketches
	Logger.Info(" --------- Sketch: " & pSketch.Name)
	For Each ent As SketchEntity In pSketch.SketchEntities
		If ent.ConstraintStatus <> ConstraintStatusEnum.kFullyConstrainedConstraintStatus Then
			Logger.Warn("** entity ConstraintStatus = {0}", ent.ConstraintStatus)
			Logger.Info(String.Format(" -- entity box: ({0},{1}) to ({2},{3})", ent.RangeBox.MinPoint.X, ent.RangeBox.MinPoint.Y, ent.RangeBox.MaxPoint.X, ent.RangeBox.MaxPoint.Y))
		End If
	Next
Next

 




Mike Deck
Software Developer
Autodesk, Inc.

Message 17 of 19
R.Mabery
in reply to: MjDeck

Mike, there may be something else going on.  I ran my code again this morning and it wasn't showing anything as underconstrained.  I shut down Inventor (Build 245 2021.1), relaunched, ran it and it was showing underconstrained.  I just ran your code against it and got the following:

TRACE|Entering rule: Rule0 (in 20003136.ipt)
INFO| --------- Sketch: Sketch32
INFO| --------- Sketch: Sketch33
INFO| --------- Sketch: Sketch34
INFO| --------- Sketch: Sketch35
INFO| --------- Sketch: Sketch36
WARN|** entity ConstraintStatus = kUnderConstrainedConstraintStatus
INFO| -- entity box: (-4.70236231460293,11.1633474405716) to (-4.70236231460293,11.1633474405716)
WARN|** entity ConstraintStatus = kUnderConstrainedConstraintStatus
INFO| -- entity box: (-6.70363618696533,13.164621312934) to (-6.70363618696533,13.164621312934)
WARN|** entity ConstraintStatus = kUnderConstrainedConstraintStatus
INFO| -- entity box: (-6.70363618696533,11.1633474405716) to (-4.70236231460293,13.164621312934)
WARN|** entity ConstraintStatus = kUnderConstrainedConstraintStatus
INFO| -- entity box: (-12.5767236901446,7.29153380975477) to (-12.5767236901446,7.29153380975477)
WARN|** entity ConstraintStatus = kUnderConstrainedConstraintStatus
INFO| -- entity box: (-12.5767236901446,7.29153380975477) to (-6.70363618696533,13.164621312934)
WARN|** entity ConstraintStatus = kUnderConstrainedConstraintStatus
INFO| -- entity box: (-11.6401295473557,6.35493966696592) to (-11.6401295473557,6.35493966696592)
WARN|** entity ConstraintStatus = kUnderConstrainedConstraintStatus
INFO| -- entity box: (-12.5767236901446,6.35493966696592) to (-11.6401295473557,7.29153380975477)
INFO| --------- Sketch: Sketch37
INFO| --------- Sketch: Sketch38
INFO| --------- Sketch: Sketch39
INFO| --------- Sketch: Sketch40
INFO| --------- Sketch: Sketch41
INFO| --------- Sketch: Sketch42
INFO| --------- Sketch: Sketch43
INFO| --------- Sketch: Sketch44
INFO| --------- Sketch: Sketch45
INFO| --------- Sketch: Sketch46
TRACE|Exiting rule: Rule0 (in 20003136.ipt)

 

Here's my original code:

 

Imports Inventor.ConstraintStatusEnum
Imports Inventor.GeometryMoveableStatusEnum

' Dim oPartDoc As PartDocument
' oPartDoc = ThisApplication.ActiveDocument

' Dim oCompDef As ComponentDefinition
' oCompDef = oPartDoc.ComponentDefinition

' Dim oSketches As PlanarSketches
' oSketches = oCompDef.Sketches

' Dim oSketch As PlanarSketch

' For Each oSketch In oSketches
	' If oSketch.ConstraintStatus = kFullyConstrainedConstraintStatus Then
		' Logger.Info("Sketch: " & oSketch.Name & " is fully constrained")
	' ElseIf oSketch.ConstraintStatus = kOverConstrainedConstraintStatus Then
		' Logger.Info("Sketch: " & oSketch.Name & " is over constrained")
	' ElseIf oSketch.ConstraintStatus = kUnderConstrainedConstraintStatus Then
		' Logger.Info("Sketch: " & oSketch.Name & " is under constrained")
	' ElseIf oSketch.ConstraintStatus = kUnknownConstraintStatus Then
		' Logger.Info("Sketch: " & oSketch.Name & " is unknown status")
	' End If
' Next

Dim oAssy As AssemblyDocument
oAssy = ThisApplication.ActiveDocument

Dim oAssyCompDef as AssemblyComponentDefinition
oAssyCompDef = oAssy.ComponentDefinition

Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAssyCompDef.Occurrences.AllLeafOccurrences

Dim oOcc As ComponentOccurrence

Dim oSketch As PlanarSketch

Dim sNotFullyConstrainedList As New ArrayList
Dim sCompsProcessed As New ArrayList

Dim sOccName as String 
Dim sFullFileName as String
Dim sSketchName as String
Dim sConcName as String

Dim oSketchObjects As ObjectCollection

For Each oOcc In oLeafOccs
	If NOT oOcc.Definition.Type = kWeldsComponentDefinitionObject Then 
		sOccName = oOcc.Name
		sFullFileName = oOcc.Definition.Document.FullFilename
		
		If sCompsProcessed.Contains(sFullFileName) Then 
			Continue For 
		Else 
			sCompsProcessed.Add(sFullFileName)
			
			Logger.Info("sOccName: " & sOccName)
			Trace.WriteLine("iLogic: sOccName " & sOccName)
			Trace.WriteLine("iLogic: sFullFileName: " & sFullFileName)
			
			Dim oSketches As PlanarSketches
			oSketches = oOcc.Definition.Sketches
			
			Dim oSketchEntity as SketchEntity
			
			For Each oSketch In oSketches
				sSketchName = oSketch.Name
				sConcName = String.Concat(sFullFileName,"_",sSketchName,"_",oSketch.ConstraintStatus)
				
				For Each oSketchEntity in oSketch.SketchEntities
					If NOT oSketchEntity.[_GeometryMoveableStatus] = kFixedGeometryMoveableStatus Then 
						sConcName = String.Concat(sFullFileName,"_",sSketchName,"_",oSketchEntity.Type,"_",oSketch.ConstraintStatus)
						
						If oSketchEntity.ConstraintStatus = kFullyConstrainedConstraintStatus Then
							' Logger.Info("Sketch: " & oSketch.Name & " is fully constrained")
							' Trace.WriteLine("iLogic: Sketch: " & oSketch.Name & " is fully constrained")
						ElseIf oSketchEntity.ConstraintStatus = kOverConstrainedConstraintStatus Then
							Logger.Info("Sketch: " & oSketch.Name & " is over constrained")
							Trace.WriteLine("iLogic: Debug Sketch: " & oSketch.Name & " is over constrained")
							
							If NOT sNotFullyConstrainedList.Contains(sConcName) Then 
								sNotFullyConstrainedList.Add(sConcName)
							End If
						ElseIf oSketchEntity.ConstraintStatus = kUnderConstrainedConstraintStatus Then
							Logger.Info("Sketch: " & oSketch.Name & " is under constrained")
							Trace.WriteLine("iLogic: Debug Sketch: " & oSketch.Name & " is under constrained")
							
							If NOT sNotFullyConstrainedList.Contains(sConcName) Then 
								sNotFullyConstrainedList.Add(sConcName)
							End If
						ElseIf oSketchEntity.ConstraintStatus = kUnknownConstraintStatus Then
							Logger.Info("Sketch: " & oSketch.Name & " is unknown status")
							Trace.WriteLine("iLogic: Debug Sketch: " & oSketch.Name & " is unknown status")
							
							If NOT sNotFullyConstrainedList.Contains(sConcName) Then 
								sNotFullyConstrainedList.Add(sConcName)
							End If
						End If
					End If 
				Next 
			Next
		End If
	End If
Next

For Each m as String In sNotFullyConstrainedList
	Trace.Writeline("iLogic: Not Fully constrained Sketches : " & m)
Next

 

 

 


Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
Message 18 of 19
2020mme013
in reply to: R.Mabery

Hi @R.Mabery 

I am trying to use this code, but "Logger" is not accessible for me. can you please tell me how to access this.

2020mme013_0-1669699711289.png

 

Message 19 of 19
R.Mabery
in reply to: 2020mme013

The logger was introduced in Inventor iLogic 2019.  


Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report