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

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
CAG_DRAFT
4647 Views, 8 Replies

iLogic to Change Sheet Name

Can it be done? 

I've seen snipppets of code to get the Sheet name but is there a way to set it via code?

 

I'm thinking it might be useful to set the sheet names to the chosen sheet format (as opposed to just 'Sheet').

 

I'm sprucing up my drawing template...

Rule #1 is for selecting sheet format (which title block/sheet size/oreintation)

Rule #2 is for setting iproperty values to populate the titleblock with info. (if required)

 

Rule #1 was based on code from S.Bixler & inventortrenches

Rule#2 was based on more code taken from here, thanks forum users.

8 REPLIES 8
Message 2 of 9
mrattray
in reply to: CAG_DRAFT

Sheet.Name is a read-write property, setting is as easy as:
Sheet.Name = "My New Sheet Name"
Mike (not Matt) Rattray

Message 3 of 9
CAG_DRAFT
in reply to: mrattray

Thanks, I was so close on my first efforts, just had the preceding syntax wrong.
("ActiveSheet.Name = ...")

Years ago I learnt a little VB but obviously I don't remember enough to avoid noob mistakes like that.
Message 4 of 9
TPDyno
in reply to: mrattray

Hi Mike

 

I am currently using the below rule to label my drawing sheets. I have some larger assemblies where some components are set to reference for that particular configuration. It would be really handy to see this in the sheet name so I can move these all to the end of the set so I know to ignore them for that particular configuration.

 

So I want to add the BOMStructure type to the sheet name, I am struggling to access this and add it to the rule, are you able to help. It doesn't matter if it read its id number or "Reference/Normal", its just to differentiate from each other.

 

SyntaxEditor Code Snippet

Sub Main
    If TypeOf ThisDoc.Document Is DrawingDocument Then
        Dim dwgDoc as DrawingDocument = ThisDoc.Document
        Dim BOMStructure As Object 
        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(32).Value + "-" + modelDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(43).Value
                If Not String.IsNullOrEmpty(prtNumber) Then
                    dwgSheet.Name = prtNumber
                End If
            End If
        Next
    End If
End Sub

 Regards,

Travis

Message 5 of 9
s1e2t3h4
in reply to: CAG_DRAFT

 A new company I am working with has a, oxyfuel cutting table and their software on the cnc machine only accepts 1 .dxf file at a time to import. 

Is there a way to change the sheet name to reflect the Part Number of an .ipt that is placed on the sheet, then to do it for multiple sheets? So I can export to .dxf and the filenames will be base off of the Sheet Names?

Message 6 of 9
n.schotten
in reply to: s1e2t3h4

Here is a bit of code i cobbled together to do just that. I've finaly got so 'upset' with the generic SHEET in the browser, making it hard to find the part sheet i'm looking for that i just went looking for code. I used the above code and copied some of my other ilogic rules that sets the iproperties based (in part) on the assembly iproperties. and now it renames the browser to the part name.

Do note that some might not get renemed due to illegal characters in the property name.

 

Sub Main
    If TypeOf ThisDoc.Document Is DrawingDocument Then
        Dim dwgDoc As DrawingDocument = ThisDoc.Document
        Dim BOMStructure As Object 
        For Each dwgSheet As Sheet In dwgDoc.Sheets
            If dwgSheet.DrawingViews.Count > 0 Then
				FNamePos = InStrRev(dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName, "\", - 1)
				docFName = Mid(dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName, FNamePos + 1, Len(dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName) - FNamePos)
'				prtNumber = iProperties.Value(docFName, "Summary", "Title")
				prtNumber = iProperties.Value(docFName,"Project", "Part number")
				If Not String.IsNullOrEmpty(prtNumber) Then
                    dwgSheet.Name = prtNumber
'					MessageBox.Show(prtNumber)
                End If
            End If
        Next
    End If
End Sub

 

Message 7 of 9
danielvdeleito
in reply to: n.schotten

Hi. Is any chance to write the sheet name with a Prompt Value.
Ex: each of my sheets have their own name I already set with a Prompt Value like
-Index
-Plan view
-Elevations
-Etc.

So I would like to see this same values in the Sheet names tree. Maybe the approach is the other way: Can I auto-populate a prompt value with the sheet name?

Thanks
Message 8 of 9

Hi! I think it should be doable via iLogic. However, sheet names have to be unique. If there is already an existing sheet with the same name, the renamed name will be rejected.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 9 of 9
youneedtodonow
in reply to: CAG_DRAFT

I DID IT!!

 

 

Sub Main
    If TypeOf ThisDoc.Document Is DrawingDocument Then
        Dim dwgDoc As DrawingDocument = ThisDoc.Document
        Dim BOMStructure As Object 
        For Each dwgSheet As Sheet In dwgDoc.Sheets
            If dwgSheet.DrawingViews.Count > 0 Then
                FNamePos = InStrRev(dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName, "\", - 1)
                docFName = Mid(dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName, FNamePos + 1, Len(dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName) - FNamePos)
                prtNumber = iProperties.Value(docFName, "Project", "Part number")
                stockNumber = iProperties.Value(docFName, "Project", "Stock number")
                If Not String.IsNullOrEmpty(prtNumber) Then
                    Dim newSheetName As String = prtNumber & " " & stockNumber
                    If IsAssemblyDocument(docFName) And Not newSheetName.EndsWith("ASS'Y") Then
                        newSheetName = newSheetName & " ASS'Y"
                    End If
                    dwgSheet.Name = newSheetName
                End If
            End If
        Next
    End If
End Sub

Function IsAssemblyDocument(docName As String) As Boolean
    Dim fileExtension As String = System.IO.Path.GetExtension(docName).ToUpper()
    Return fileExtension = ".IAM"
End Function

 

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

Post to forums  

Autodesk Design & Make Report