Hi,
Does anyone know how to reference the drawign sheet number using iLogic? I see on the snippets on the side a way to reference the sheet name, but I only want the number. To get the name it is ActiveSheet.Name, but ActiveSheet.Number does not work. Getting the name give something like ASSM:1, so if there was a way to take that and subtract the colon and everything before it that would work also. I am not a programmer, I've just taked some programs I found online and modified them a little to do what I want to do, but this is holding me back a bit.
Overall, I'm trying to modify the drawing view label to have a project number, referenced from the drawign iProperties, a view label, and sheet number, and then save that info in an iproperty of the part, and then reference that in the BOM so it automatically labels all of the views and fills out a column of the BOM to reference which page and view to find the parts of the assembly. I have everything working except for the sheet number.
I would greatly appreciate any help.
Thanks,
Jeremy
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi jestes,
Here is an example:
Dim oSheet As Sheet Dim SheetNumber as String i = 1 For Each oSheet In ThisApplication.ActiveDocument.Sheets SheetNumber = Mid(oSheet.Name, InStr(1, oSheet.Name, ":") + 1) MessageBox.Show(SheetNumber, oSheet.Name) i=1+1 Next
Or something like this to get the active sheet only:
oDoc = ThisDoc.Document
SheetNumber = Mid(oDoc.ActiveSheet.Name, InStr(1, oDoc.ActiveSheet.Name, ":") + 1)
MessageBox.Show(SheetNumber, oDoc.ActiveSheet.Name)
Keep in mind you might have better luck searching and asking questions of this type on the Inventor Customization forum:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Thanks Curtis, that worked great. I think this will help us out a lot.
Jeremy
Hey Curis, I found a problem in my code I was hoping you could help me with again. For some reason what I'm doing does not work with any parts made by the frame generator. Everything else I've tried seems to work well. What I want is to get a project number-view label-sheet number sent to the Status iPropertie of the part or assembly that is inside the view. Then I can use the Status iProperty inside my view label and the BOM. I'll attach my code below. If you wouldn't mind looking at it I would appreciate it. Thanks a lot, I appreciate the help.
Jeremy
'start of ilogic codeDim oDoc As DrawingDocument: oDoc = ThisDoc.Document Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews Dim oView As DrawingView Dim SheetNumber As String i =1 oSheets = oDoc.Sheets For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews 'capture the current view label
ViewLabel = oView.Name oModelName = _ oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName Try SheetNumber =Mid(oSheet.Name, InStr(1, oSheet.Name, ":") + 1) i=1+1 iProperties.Value(oModelName, "Status", "Status") = _
iProperties.Value("Project", "Project")+"-"+ViewLabel+SheetNumber 'Send view label items to models Status iProperty
'Use Status iProperty for view label
Catch 'do nothing if error
End Try 'End If
Next Next 'end of ilogic code
Hi jestes,
The problem is with the display name of the Frame Generator parts (and many other Content Center parts). Basically Autodesk is setting the display name as an override in their Content Center tables, and therefore your code was reading in something such as ANSI 2x2x3_16 00000009 rather then ANSI 2x2x3_16 00000009.ipt.
Adding a line of code to reset the display name to nothing, allows the part to return back to the default display name.
oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName = ""
This is the same as doing this:
Here's your updated rule.
'start of ilogic code Dim oDoc As DrawingDocument: oDoc = ThisDoc.Document Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews Dim oView As DrawingView Dim SheetNumber As String i =1 oSheets = oDoc.Sheets For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews 'capture the current view label ViewLabel = oView.Name 'reset the display name oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName = "" 'get the display name oModelName = _ oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName Try 'get the sheet number SheetNumber =Mid(oSheet.Name, InStr(1, oSheet.Name, ":") + 1) i=1+1 iProperties.Value(oModelName, "Status", "Status") = _ iProperties.Value("Project", "Project")+"-"+ViewLabel+SheetNumber 'Send view label items to models Status iProperty 'Use Status iProperty for view label Catch 'do nothing if error End Try Next Next
'end of ilogic code
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Thanks Curtis,
That fixed that, but I did run into a couple more issues. Is there any way to make it work with iParts? I get an error if there is an iPart on the sheet. I might have to use a different iProperty other than Status to work with iParts because I don't see that as being on that you can update in the iPart table. If this is not doable or very difficult I can just update these views manually. It seems to still work for the rest of the views.
Also, for some reason it works fine on 2 of the machines I tried it on, but it won't work on one of our other employees machines. It doesn't give any errors, and as far as I know it runs the program, but it just doesn't do anything. No changes to the properties. Any idea why it would be different on one machine? I have the rule saved in a template, so we're both opening the exact same thing and both on Inventor 2013. I don't think he has the newest service pack installed, so that might be it.
Thanks for the help, I really appreciate it.
Jeremy
Hi all:
Using the above code, I've made some modifications for my purposes. I want to show a detailed component's 'detailed on' sheet number in the parts list. We use the Vendor iProperty for the sheet number, and use four-digit sheet numbers.
I created a test .idw with three sheets named 6000, 6001, and 6002, then put a single view each of two unique components on each sheet, then ran the below rule. It gave the expected output just ONCE, i.e. populating each component's Vendor iProperty with the sheet number on which it was detailed. Despite repeated running of the rule, after closing and reopening the .idw, and starting and restarting Inventor, it now does not update the components. There were no code changes between the attempts.
Can someone please review the below and advise a solution? Thanks!
SyntaxEditor Code Snippet
Sub Main() Dim oDoc As DrawingDocument: oDoc = ThisDoc.Document Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews Dim oView As DrawingView Dim SheetNumber As String 'i =1 oSheets = oDoc.Sheets For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName="" oModelName = oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName oModelName = oModelName + ".ipt" 'display the active view's component file name as visual check MessageBox.Show(oModelName) Try 'get the sheet number SheetNumber = Mid(oSheet.Name, 1, 4) 'display the sheet number as visual check MessageBox.Show(SheetNumber) 'update the component's Vendor iproperty with the current sheet number iProperties.Value("oModelName", "Project", "Vendor") = SheetNumber 'i=i+1 Catch 'do nothing if error End Try Next Next End Sub
I did get it to run with the below code modifications. Now I need a way to limit the interrogation to just the first (primary, main) view placed, rather than opening every view. Not critical for parts normally, but assemblies can run across several sheets and I don't want the latter sheet numbers replacing the primary sheet number, as that is where we put our parts list.
SyntaxEditor Code Snippet
Sub Main() Dim oDoc As DrawingDocument: oDoc = ThisDoc.Document Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews Dim oView As DrawingView Dim SheetNumber As String oSheets = oDoc.Sheets For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName="" oModelName = oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName 'get file type for extension selection oViewModelType = oView.ReferencedDocumentDescriptor.ReferencedDocument If oViewModelType.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then oModelName = oModelName + ".ipt" Else oModelName = oModelName + ".iam" End If Try 'get the sheet number SheetNumber = Mid(oSheet.Name, 1, 4) 'update the component's Vendor iproperty with the current sheet number iProperties.Value(oModelName, "Project", "Vendor") = SheetNumber InventorVb.DocumentUpdate() Catch 'do nothing if error End Try Next Next ThisDoc.Save End Sub
Another workaround that works if you don't use the Sheet Revision property, is to create some ilogic code that updates each sheet's revision number to the page numbering you want and display that in your drawing.
For instance what I did:
Sub Main() Dim oDoc As DrawingDocument: oDoc = ThisDoc.Document Dim oSheets As Sheets Dim oSheet As Sheet Dim sheet_base_name As String Dim sheet_num As String oSheets = oDoc.Sheets sheet_base_name = PageName i = PageOffset For Each oSheet In oSheets sheet_num = CStr(i) oSheet.Name = sheet_base_name + sheet_num oSheet.Revision = sheet_num i = i + 1 Next End Sub
PageName and PageOffset are parameters declared in the drawing to denote how each sheet is named and from which number to start counting
This thread is very helpful! Thank you (everyone) for sharing your expertise and knowledge!
We've borrowed Jeremy's code, tweaked it a bit for our standards and only have one thing left to be desired. Our sheet numbers are always three digits. I added "00" to proceed the sheet number assigned by the rule, but, (of course) now any sheet greater than "010" are populated as "0010."
Is there a magic bullet portion of code that will control desired leading zeros (or lack thereof)?
Any help is greatly appreciated. None of us here are trained or knowledgeable about creating Inventor rules without some great examples or something to start with.
Thank you in advance!
-Adam
Hi @amassicotte
I think this should take care of it... I just added the line in red.
edit: make that the blue line ( I thought of a mistake as soon as I posted, and fixed it)
note that I didn't test it, so just post back if it doesn't work.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Dim oDoc As DrawingDocument : oDoc = ThisDoc.Document Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews Dim oView As DrawingView Dim SheetNumber As String i =1 oSheets = oDoc.Sheets For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews 'capture the current view label ViewLabel = oView.Name oModelName = _ oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName Try SheetNumber = Mid(oSheet.Name, InStr(1, oSheet.Name, ":") + 1) SheetNumber = IIf (SheetNumber < 10, "00" + CStr(SheetNumber), "0" + CStr(SheetNumber)) i=1+1 iProperties.Value(oModelName, "Status", "Status") = _ iProperties.Value("Project", "Project")+"-"+ViewLabel+SheetNumber 'Send view label items to models Status iProperty 'Use Status iProperty for view label Catch 'do nothing if error End Try 'End If Next Next
Hi everyone.
I have an almost similar problem and hope someone can help me.
I need my drawing sheets to start from a specific number (input by the user). In other words, I want to have a page number at the bottom of each page consisting of "Sheet number" + a number given by the user. Could anyone please help me?
Thanks
Can't find what you're looking for? Ask the community or share your knowledge.