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 to change sheet name to equal Part Number.

58 REPLIES 58
SOLVED
Reply
Message 1 of 59
mstumbo
6924 Views, 58 Replies

iLogic to change sheet name to equal Part Number.

I would like to have an iLogic rule that changes the active sheet name to the Models Part Number property.

 

I tried ActiveSheet.name = iProperties.Value("Project", "Part Number"), but

 

get an Error: Property 'Name' is 'ReadOnly'.

 

 

Any help would be greatly appreciated.

 

Thanks,

 

 

 

 
58 REPLIES 58
Message 2 of 59
alyssaweaver
in reply to: mstumbo

http://forums.autodesk.com/t5/Inventor-General/iLogic-to-Change-Sheet-Name/td-p/4581545

"Sheet.Name is a read-write property, setting is as easy as:

Sheet.Name = "My New Sheet Name"

Mike (not Matt) Rattray"

 

So maybe edit that...?

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
Message 3 of 59
mstumbo
in reply to: alyssaweaver

I got the snippit: ActiveSheet.Sheet.Name = iProperties.Value("Project", "Part Number" to change all the sheet names to the part number of the drawing file iproperty Part number, however...

 

What I am trying to accomplish is:

 

I have the assembly view of say a nightstand on sheet 1. On the following sheets I have drawing views for each component (one component per sheet). 

I have the Part Number property mapped to my Title Block that populates with the Model property Part Number in each sheet. My rule would need to change the sheet name to that property of the Title block. This would make finding part drawings in the Vault web client a lot easier. And eleviate the manual entry process.

 

 I found this code that works, but it errors out on the sheet that has the assembly view (sheet one). When I deleted the sheet with the assembly view It cycled through and changed the sheet names just fine.

 

 

Dim oSheets As Sheets

oSheets = ThisDoc.Document.sheets

Dim oSheet As Sheet

For Each oSheet In oSheets

oSheet.activate

Dim oDrawingView As DrawingView

oDrawingView = oSheet.DrawingViews(1)

oModelName = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName

oDesc = iProperties.Value(oModelName, "Project", "Part Number")

oSheet.Name = oDesc

Next

 

 

Thanks, Appreciate the help.

 

 

  

Message 4 of 59
rjay75
in reply to: mstumbo

Here's some alternate code. Instead looking at the drawing view, and using the display name it just gets the name from the current model being displayed in the first view directly.

 

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("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(5).Value
                If Not String.IsNullOrEmpty(prtNumber) Then
                    dwgSheet.Name = prtNumber
                End If
            End If
        Next
    End If
End Sub
Message 5 of 59
mstumbo
in reply to: rjay75

Bingo! Yep that did it.

 

Thanks Rjay75!

Message 6 of 59
KevinMyers
in reply to: mstumbo

I’ve been trying to do something like this for the past 3 months without success and this comes very close to what I want.  What lines would I need to add to get the “Description” iproperty from the part model and combine it after the “PartNumber” iproperty then use that to rename the drawing sheet?

Thanks for the help.

Message 7 of 59
rjay75
in reply to: KevinMyers

The other was older code. Here's code to do what you want.

 

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
Message 8 of 59
KevinMyers
in reply to: rjay75

Thank you very much for the quick reply.  I'll have to wait until Tuesday when I get back into the office to put this in my template.

Thanks again.

Message 9 of 59
KevinMyers
in reply to: KevinMyers

This worked great.

Thanks again

Message 10 of 59
Frank-Flipsen
in reply to: KevinMyers

Hi, I have no experiance with I logic, but the code would be incredebly usefull to me.

how do I set up this code in I logic? 

 

Many thanks 

 

Frank

Message 11 of 59
Frank-Flipsen
in reply to: KevinMyers

Hi, I have no experiance with I logic, but the code would be incredebly usefull to me.

how do I setup this code in I logic? 

 

Many thanks 

 

Frank

Message 12 of 59
GosponZ
in reply to: Frank-Flipsen

In iLogic Rules Tab add new Rule. Copy and paste code in editor. Done!

Message 13 of 59
Frank-Flipsen
in reply to: GosponZ

Sorry for my late responce, the allert mail went into my spam folder. This is fantastic,  thank you for the advice and the code. If this is posibble that I need to start learning I logic rules and codes. I just changed 180 sheets names with one click of a button, Happy days.

Message 14 of 59
Stansteel
in reply to: rjay75

Hello, First of all this ilogic rule works great! It does exactly what I want, but, of course, I'd like to add a couple of situations to it. Let me explain. Situation #1 (Normal) - In a normal situation, we detail an assembly on the first of many sheets and the following sheets would be one part per drawing. Here, this code works great. For example, our sheet names might look like this: 1739-MHE-05-A1 1739-MHE-05-01 1739-MHE-05-02 1739-MHE-05-03 Situation #2 - If we run out of room on the first sheet, we might need to create many sheets to do so. Example: 1739-MHE-05-A1 SHEET 1 1739-MHE-05-A1 SHEET 2 1739-MHE-05-A1 SHEET 3 1739-MHE-05-01 1739-MHE-05-02 1739-MHE-05-03 Situation #3 - Should these drawings ever get revised, we need the revision level at the end of the name using the Sheet Revision property of the drawing. Example: 1739-MHE-05-A1 SHEET 1 - REV A 1739-MHE-05-A1 SHEET 2 - REV A 1739-MHE-05-A1 SHEET 3 - REV A 1739-MHE-05-01 1739-MHE-05-02 - REV A 1739-MHE-05-03 So, I'd like to pull the part number from the first view, add sheets 1, 2, 3 etc. if needed, and add the revison level if one exists. Can this be done? Can someone help me with this? Thank you in advance. Nate
Message 15 of 59
rjay75
in reply to: Stansteel

Try this.

 

Sub Main
  If TypeOf ThisDoc.Document Is DrawingDocument Then
    Dim dwgDoc as DrawingDocument = ThisDoc.Document'
    Dim sheetNames As New Dictionary(Of String, ArrayList)
    'Count all the sheets per part
    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
        If Not String.IsNullOrEmpty(prtNumber) Then
          If Not sheetNames.ContainsKey(prtNumber) Then
            sheetNames.Add(prtNumber, New ArrayList({1, 0}))
          Else
            sheetCount = sheetNames(prtNumber)(0)
            sheetCount = sheetCount + 1
            sheetNames(prtNumber)(0) = sheetCount
          End If
        End If
      End If
    Next
    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
        prtRev = modelDoc.PropertySets("Summary Information").Item("Revision Number").Value
        If Not String.IsNullOrEmpty(prtNumber) Then
          If Not String.IsNullOrEmpty(prtRev) Then
            prtRev = String.Format(" - Rev {0}", prtRev)
          End If
          sheetOf = ""
          sheetCount = sheetNames(prtNumber)(0)
          If sheetCount > 1 Then
            sheetNames(prtNumber)(1) = sheetNames(prtNumber)(1) + 1
            sheetOf = String.Format(" Sheet {0}", sheetNames(prtNumber)(1))
          End If
          dwgSheet.Name = prtNumber & sheetOf & prtRev
        End If
      End If
    Next
  End If
End Sub

 

Cleaned up the spaces to see the lines easier.

 

Message 16 of 59
Stansteel
in reply to: rjay75

Thanks for the quick reply. Here are errors that popped up. Line 8 : End of statement expected. Line 9 : End of statement expected. Line 24 : End of statement expected. Line 25 : End of statement expected. Nate
Message 17 of 59
rjay75
in reply to: Stansteel

I edited the post to clean up the spacing. It may be extra 'returns' in formatting the code.

 

Attached is the code in a file.

Message 18 of 59
Stansteel
in reply to: Stansteel

Ok, I was able to get past the errors by copying and pasting code from a previous code. I agree with the spacing. So, now it's working...almost perfectly. I believe there are actually (2) revision properties. I'm looking for the "Sheet Revision" property in which the revision block controlls. Can you make this revision level only show up if a letter is present? Thanks, Nate
Message 19 of 59
rjay75
in reply to: Stansteel

Unfortunately I can't locate the Revision property of a sheet. It seems to not be exposed by the api.

Message 20 of 59
Stansteel
in reply to: rjay75

In effort to possibly locate this property, I'll explain how I'm using it. In my title block, I have text that is using this property. The "Type" field set to "Sheet Properties" and the "Property" field set to "Sheet Revision". Other choices here would be "Sheet Number" and "Sheet Size". I believe the actual letter is inputted in the "Edit Sheet" window on any given sheet. If you right click on a sheet, choose Edit Sheet...the letter is in the "Revision" field. Does any of this help?

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

Post to forums  

Autodesk Design & Make Report