iLogic V2021 problem

iLogic V2021 problem

kresh.bell
Collaborator Collaborator
568 Views
9 Replies
Message 1 of 10

iLogic V2021 problem

kresh.bell
Collaborator
Collaborator

Hi,

this iLogic worked perfectly for me until the V2021. Can anyone help? When I run it, Inventor crashes

 

'check for custom iProperty and add it if not found
Dim prefix As String = "Prefix"
customPropertySet = ThisDoc.Document.PropertySets.Item _
("Inventor User Defined Properties")

Try
         prop= customPropertySet.Item(prefix)
Catch
      ' Assume error means not found
            customPropertySet.Add("", prefix)
End Try

'write the part number to the Prefix iProperty if it is empty
If iProperties.Value("Custom", "Prefix") = "" Then
iProperties.Value("Custom", "Prefix") = iProperties.Value("Project", "Part Number") & "_"
Else
End If

'check that this active document is a part file   
Dim partDoc As PartDocument
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
MessageBox.Show ("Please open a part document", "iLogic")
End If

'define the active document
partDoc = ThisApplication.ActiveDocument
Dim solid As SurfaceBody
Dim i As Integer

'get input from user
prefix = InputBox("Enter a prefix for the solid body names", "iLogic", iProperties.Value("Custom", "Prefix"))

'write input back to custom iProperty
iProperties.Value("Custom", "Prefix") = prefix
i = 1
'rename all solid bodies incrementing suffix
For Each solid In partDoc.ComponentDefinition.SurfaceBodies
solid.Name = prefix + Iif(i < 10, "0" + CStr(i), CStr(i))
i = i + 1
Next

 

 

0 Likes
569 Views
9 Replies
Replies (9)
Message 2 of 10

kresh.bell
Collaborator
Collaborator

... same problem with this iLogic

 

Public Sub Main()


Dim a As Application
 a = ThisApplication
 

Dim b As PartDocument
 b = a.ActiveDocument
 
 Try
	 
 Dim p As Inventor.Property = b.PropertySets.Item(4).Add("", "Prefix")
 
 Catch
	 
 End Try
	 

Dim c As SurfaceBody
Dim d As SurfaceBodies

Dim E As SelectSet
E = b.SelectSet

If E.Count = 0 Then
MsgBox ("select something")

Else

Dim i As Integer

'get input from user
Dim prefix As String

prefix = InputBox("Enter a prefix for the solid body names", "iLogic", iProperties.Value("Project", "Part Number") & "_")

'write input back to custom iProperty
'iProperties.Value("Custom", "Prefix") = prefix
i = 1
'rename all solid bodies incrementing suffix
For Each c In E


c.Name = prefix + IIf(i < 10, "0" + CStr(i), CStr(i))
i = i + 1
Next
'e.Name = ""
End If

End Sub
0 Likes
Message 3 of 10

Michael.Navara
Advisor
Advisor

Hi,

I test your code snippets and both woks fine as local rule. Without crash.

(WIN 10 + Inventor 2021 (x64, Build 183)

0 Likes
Message 4 of 10

kresh.bell
Collaborator
Collaborator

I don't understand, what could be the problem? I run this iLogic as an external rules 

0 Likes
Message 5 of 10

marcin_otręba
Advisor
Advisor

I tried and both work fine. Could you provide your sample files to test it ?

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 6 of 10

Sergio.D.Suárez
Mentor
Mentor
A tip, when you find bugs in ilogic that work in other inventor versions and don't throw bugs, try to fully define the variables. It has happened to me that by not defining all the variables some codes threw errors.

 

'check for custom iProperty and add it if not found
Dim prefix As String = "Prefix"
Dim customPropertySet As Inventor.PropertySet = ThisDoc.Document.PropertySets.Item _
("Inventor User Defined Properties")

Try
         prop= customPropertySet.Item(prefix)
Catch
      ' Assume error means not found
            customPropertySet.Add("", prefix)
End Try

'write the part number to the Prefix iProperty if it is empty
If iProperties.Value("Custom", "Prefix") = "" Then
iProperties.Value("Custom", "Prefix") = iProperties.Value("Project", "Part Number") & "_"
Else
End If

'check that this active document is a part file   
Dim partDoc As PartDocument
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
MessageBox.Show ("Please open a part document", "iLogic")
End If

'define the active document
partDoc = ThisApplication.ActiveDocument
Dim solid As SurfaceBody
Dim i As Integer

'get input from user
prefix = InputBox("Enter a prefix for the solid body names", "iLogic", iProperties.Value("Custom", "Prefix"))

'write input back to custom iProperty
iProperties.Value("Custom", "Prefix") = prefix
i = 1
'rename all solid bodies incrementing suffix
For Each solid In partDoc.ComponentDefinition.SurfaceBodies
solid.Name = prefix + IIf(i < 10, "0" + CStr(i), CStr(i))
i = i + 1
Next

 I hope you can solve the problem soon. Cheers


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 7 of 10

kresh.bell
Collaborator
Collaborator

I still have a problem. Can you try on this file?

0 Likes
Message 8 of 10

marcin_otręba
Advisor
Advisor

it is not ilogic fault. Try to change any first body name manually, and inventor will crush as well.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 9 of 10

marcin_otręba
Advisor
Advisor

i tried on my file with multiple bodies and it works.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 10 of 10

kresh.bell
Collaborator
Collaborator

yes, the problem seems to be something else, thanks guys

0 Likes