Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Add If and Then to this drawing sheet naming iLogic Code

Anonymous

Add If and Then to this drawing sheet naming iLogic Code

Anonymous
Not applicable

Hey,

 

I have been using this code below, i did not create it, but i am wishing to add If and Then statement to it, but i have no idea where to start, is someone able to re-write this to include those statements

 

SyntaxEditor Code Snippet

Sub Main()
'Purpose: Push file name to sheet name'21-Sept-16
 
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oDrawingView As DrawingView

'Iterate through sheets
For Each oSheet In oDoc.Sheets
    'Grab the first drawing view on the sheet
    oDrawingView = oSheet.DrawingViews(1)

    'Grab the model of the first drawing view
    oModel = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument 

    'Grab the custom iproperty of the first drawing view model
    oModel1 = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
    o_iProp = iProperties.Value(oModel1, "Custom", "RevisionUK")  

    'set sheet name to filename and custom iprop from model
    oSheet.Name = System.IO.Path.GetFileNameWithoutExtension(oModel.FullFileName)& " - " & o_iProp
End Sub
0 Likes
Reply
Accepted solutions (1)
705 Views
8 Replies
Replies (8)

jletcher
Advisor
Advisor

Going to need more information..

 

Like what do you want the "If and Then" statement to do?

0 Likes

Anonymous
Not applicable

Im having an issue with running the code on another pc and wondering if i give more detail in the code it may work? 

0 Likes

jletcher
Advisor
Advisor

I don't think adding a "if then" is going to do anything for you.

 

 

What are the issues on other machine?

0 Likes

Anonymous
Not applicable

I get the error on others pc that Object reference is not set to an instance of an object? Any ideas why? Works fine on my machine 

0 Likes

jletcher
Advisor
Advisor

Are you using the same drawing?

0 Likes

Anonymous
Not applicable

Yes,

 

all drawings work on mine, but the same ones do not work on other machines. 

0 Likes

jletcher
Advisor
Advisor

It errors right off the bat for me is there more to this?

 

there is a "For" statement but "Next"

 

1st error.JPG

0 Likes

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi Grant.ParryGS9ZQ,

 

There are many people that work to keep the forum tidy, so please try not to create duplicate/redundant postings, as it spreads resources thin and makes future search results for similar issues fragmented and less effective. If you do determine that it best to create duplicate/redundant postings though, please take the time to provide links to them.

 

duplicate/redundant postings:

https://forums.autodesk.com/t5/inventor-forum/object-reference-not-set-error-when-running-ilogic-cod...

https://forums.autodesk.com/t5/inventor-customization/ilogic-rule-object-reference-not-set-to-an-ins...

 

Also in the future, for programming questions it's generally better to use the Inventor Customization forum:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

With all of that in mind for the future, let's get back to the issue:

 

A couple of questions: 

  • Do the other machines have Windows set up to show file extensions? I think this might cause this issues you are seeing, if they are not showing file extensions.
  • On the other machines is the file saved, meaning does it have a file name and path, or are you running it from a new file created from a template that has not yet been saved. Based on the code snippet, that would be one cause of this issue. 
  • Another cause would be a file that does not have a referenced model. For instance one with no drawing view.

Edit: I see the last 2 questions have been answered as I was typing.

 

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