Sheet Rename i-logic

Sheet Rename i-logic

estewart3E8B6
Enthusiast Enthusiast
645 Views
7 Replies
Message 1 of 8

Sheet Rename i-logic

estewart3E8B6
Enthusiast
Enthusiast

Could someone Please 🙏 modify the code below to use a custom i-property <MARK> in place of the ("Part Number")

and remove the ("Description") 

thanks in advance.

 

Sub Main
If TypeOf ThisDoc.Document Is DrawingDocument Then
Dim dwgDoc As DrawingDocument = ThisDoc.Document
For Each dwgSheet As Sheet In dwgDoc.Sheets
If dwgSheet.DrawingViews.Count > 0 Then
modelFile = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName
modelDoc = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
prtNumber = modelDoc.PropertySets("Design Tracking Properties").Item("Part Number").Value & " - " & _
modelDoc.PropertySets("Design Tracking Properties").Item("Description").Value
If Not String.IsNullOrEmpty(prtNumber) Then
dwgSheet.Name = prtNumber
End If
End If
Next
End If
End Sub

0 Likes
Accepted solutions (1)
646 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

Here is a list of all properties and a few samples.

 

https://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html

 

Assuming MARK is coming from the model you can do this. 

Create a new variable called Mark then change the property set name to “Inventor User Defined Properties” then change the property your targeting and your done.  

 

 Mark =  modelDoc.PropertySets("Inventor User Defined Properties").Item("MARK").Value 

Delete prtNumber and it’s associate lines and insert the above piece of code and then change Mark wherever prtNumber appears. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 8

estewart3E8B6
Enthusiast
Enthusiast

Alen,

Thank you for your reply, I zero experience with i-logic could you possibly edit the code or high light the text that needs to be removed and where i need to insert the text you suggested. 

I would appreciate any help you have to offer. 

thanks, Ed

0 Likes
Message 4 of 8

JhoelForshav
Mentor
Mentor

Try this @estewart3E8B6 

Sub Main
If TypeOf ThisDoc.Document Is DrawingDocument Then
Dim dwgDoc As DrawingDocument = ThisDoc.Document
For Each dwgSheet As Sheet In dwgDoc.Sheets
If dwgSheet.DrawingViews.Count > 0 Then
modelFile = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName
modelDoc = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
mark = modelDoc.PropertySets("Inventor User Defined Properties").Item("MARK").Value
If Not String.IsNullOrEmpty(mark) Then
dwgSheet.Name = mark
End If
End If
Next
End If
End Sub
0 Likes
Message 5 of 8

estewart3E8B6
Enthusiast
Enthusiast

Thank You for your reply. I received the following,

Error in rule: SHEET RENAME 2, in document: KING POST ARRANGEMENT.idw

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 6 of 8

JhoelForshav
Mentor
Mentor

@estewart3E8B6 

You didn't attach all the necessary files. Theres a derived part and some image for the drawing that these files reference as well. I did manage to open the drawing and part by skipping these references though, and it works fine for me...

0 Likes
Message 7 of 8

JhoelForshav
Mentor
Mentor
Accepted solution

However, that error message would show if the custom property "MARK" doesn't exist in the model document. Try this code instead that gives you a warning if the property doesn't exist 🙂

Sub Main
If TypeOf ThisDoc.Document Is DrawingDocument Then
Dim dwgDoc As DrawingDocument = ThisDoc.Document
For Each dwgSheet As Sheet In dwgDoc.Sheets
If dwgSheet.DrawingViews.Count > 0 Then
modelDoc = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
Try
mark = modelDoc.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}").Item("MARK").Value
Catch
	MsgBox("The custom property ""MARK"" doesn't exist in the part " & modelDoc.FullFileName)
End Try
If Not String.IsNullOrEmpty(mark) Then
dwgSheet.Name = mark
End If
End If
Next
End If
End Sub
0 Likes
Message 8 of 8

estewart3E8B6
Enthusiast
Enthusiast

Thanks again, did you run the SHEET RENAME 2 Rule,  or the SHEET RENAME  which uses the "Part Number" Not <Mark>.

Could you please attach the files that work for you.

Ed

0 Likes