iLoigc rule to create sheet with views.

iLoigc rule to create sheet with views.

Brian.Price
Advocate Advocate
1,981 Views
24 Replies
Message 1 of 25

iLoigc rule to create sheet with views.

Brian.Price
Advocate
Advocate

Hello,

 

Right now this is more of a how to approach question. My skill level with ilogic isn't very high and I could probably do with some VBA classes, but I am very good at reverse engineering the code and understanding its use and function.

 

My current thinking is to use the BOM to get the information I need to make this new rule run.

 

I created a rule that will allows the user to select a file, in the open file window, that will then create a new sheet with views automatically placed in locations along with a parts list, title block, border, and automated center lines. It will also allow pages to be placed manually as well.

 

What I want to do is take this to the next level by Inventor accessing the sub assemblies in the Structured BOM and generating those sheets for each sub assembly. One issue I see is that with a few hundred sub assemblies I don't want them all in one drawing file as that will make Inventor cry. I was thinking of adding a variable parameter to decide which sub assemblies to add based on BOM item numbers. Example: If parameter is >=1 and <=50 it would create sheets for items 1-50.

 

The things I am looking for is the API functions for Inventors BOM. (I could honestly use a general list of API for inventor)

How to retrieve the file path from the BOM and have the rule run for each row of the BOM.

Make the output variable depending on the range of item numbers.

 

This is a pretty big undertaking for me and I appreciate any help or input.

0 Likes
Accepted solutions (1)
1,982 Views
24 Replies
Replies (24)
Message 2 of 25

chandra.shekar.g
Autodesk Support
Autodesk Support

@Brian.Price,

 

Hoping that below iLogic code may be helpful.

 

Public Sub PartsList()
    Dim oDoc As DrawingDocument
    oDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    oSheet = oDoc.ActiveSheet
    
    Dim oPartslist As PartsList
    oPartslist = oSheet.PartsLists.Item(1)
    
    Dim oPartsRow As PartsListRow
    For Each oPartsRow In oPartslist.partsListRows
        Debug.Print oPartsRow.ReferencedFiles.Item(1).FullFileName
    Next
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 25

Brian.Price
Advocate
Advocate

Thanks for the reply.

 

Once I get the file paths from the code you gave, would I then need to add that to an array list in order to tell it which ones I want to use? 

 

I don't think I'm coming close to understanding the use of the code you provided.

 

I also tried running the rule on a single item in the parts list but it kept giving me an error.

 

        Debug.Print oPartsRow.ReferencedFiles.Item(1).FullFileName

Method of arguments must be enclosed in parentheses.

0 Likes
Message 4 of 25

chandra.shekar.g
Autodesk Support
Autodesk Support

@Brian.Price wrote:

Hello,

 

Right now this is more of a how to approach question. My skill level with ilogic isn't very high and I could probably do with some VBA classes, but I am very good at reverse engineering the code and understanding its use and function.

 

My current thinking is to use the BOM to get the information I need to make this new rule run.

 

I created a rule that will allows the user to select a file, in the open file window, that will then create a new sheet with views automatically placed in locations along with a parts list, title block, border, and automated center lines. It will also allow pages to be placed manually as well.

 

What I want to do is take this to the next level by Inventor accessing the sub assemblies in the Structured BOM and generating those sheets for each sub assembly. One issue I see is that with a few hundred sub assemblies I don't want them all in one drawing file as that will make Inventor cry. I was thinking of adding a variable parameter to decide which sub assemblies to add based on BOM item numbers. Example: If parameter is >=1 and <=50 it would create sheets for items 1-50.

 

The things I am looking for is the API functions for Inventors BOM. (I could honestly use a general list of API for inventor)

How to retrieve the file path from the BOM and have the rule run for each row of the BOM.

Make the output variable depending on the range of item numbers.

 

This is a pretty big undertaking for me and I appreciate any help or input.


@Brian.Price ,

 

For the highlighted red line, code is given.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 25

Brian.Price
Advocate
Advocate

I understand that is how to get the file path but I don't know what to do with it when I have it.

0 Likes
Message 6 of 25

tjvz85
Enthusiast
Enthusiast

Hi Brian,

 

This is quite the endeavour and I would be very interested to hear how you progress. Have you been able to figure out what to do after extracting the file paths from the BOM?

 

I am unable to help in this regard, as I myself need a better understanding of the code. I do however meddle in iLogic and use it often for more simple tasks.

 

I wanted to ask if you could help me. We make a separate IDW for each component (Sub assy, Weldment and Parts) and I would like to adjust our Assy/Weldment idw templates to have a Manufacturer specific parts list on the second page. The parts list style has already been created, I just want Inventor to check what component is one the first page, and automatically place the parts list on the second page. The second page will always be A4 landscape with it's own title block.

I would secondarily like to have the title block of this page call the details (part- & stock number) from the model on the first page.

 

Hoping you can help, or even show me in the right direction.

Good luck with your CreateNewSheet rule.

0 Likes
Message 7 of 25

Brian.Price
Advocate
Advocate

Unfortunately time has not been allowing me to progress on this rule. Another road block is getting the file location from the parts list and injecting that into the code. I am guessing I will need and array command to do it but I am not sure.

In the mean time I am exporting my structure BOM with file paths and copy pasting them from the excel file into the command prompt that pops up with my rule. It still takes time but is much faster than what I was doing as it is a lot more automated.

 

As for your parts list page, I am guessing it is a parts list only page with no model on it? If so you could use the code to place a view off the paper space of the model you want the parts list tied too, that then places the parts list with style in the location you write into the rule. With the model on the page the title block can automatically fill in the Part # and Stock # or other iproperties.

0 Likes
Message 8 of 25

tjvz85
Enthusiast
Enthusiast
Accepted solution

I feel silly to ask, but how and where do you execute your rule? I have not been able to see how it works.

 

Our R&D start-up is collaborating with another company and I want create automation in our new file templates, especially for the drawing environment. They manually put an assembly/weldment model off paper on the second page to populate the title block and to which the parts list is tied, so automating this process will be great. The first page has exactly the same model reference and parts list (in a different style) so if the second page could just call properties from the model in the active drawing file, it would be even greater.

 

I have been on the forum for some time now, looking for other rules/automation like how to call the appearance of the weldment on the first sheet to the title block. Challenge is that within the weldment.iam, appearance overrides are applied to parts and not the component as a whole, so can you get the appearance from the Top Assy?

Anyway, below are two threads I thought might assist(or not) in getting your file paths from the parts list into the code. If it doesn't help, and you get the time, I think the guy on the forum with the handle MegaJerk can be of assistance. He is in the first thread.

 

https://forums.autodesk.com/t5/inventor-customization/ilogic-how-to-run-an-assembly-level-rule-from-...

 

https://forums.autodesk.com/t5/inventor-customization/ilogic-arraylist-acting-strange/m-p/3806401#M4... 

0 Likes
Message 9 of 25

Brian.Price
Advocate
Advocate

My rule runs off of the selections made in a form. The form has a preset list of parameters to choose from. After the selections there is a button that runs the rule. I also added a macro button to my ribbon as to run the rule too. That way if I'm doing the same thing over and over I don't need the form open.

0 Likes
Message 10 of 25

tjvz85
Enthusiast
Enthusiast

Hi @Brian.Price ,

 

Just to confirm, do you have the parameters, for selection in your form, set up in your model before hand?

 

I am busy with a global form and I am looking for a way to bypass the creation of parameters in the model file, so that everything can just be done from the form. You marked my previous post as a solution. Can you please share with me what it solved for you? Were you able to solve the adding of the file paths to an array?

 

Any assistance will be much appreciated. We are busy with about the same as you, so if you have any questions, please feel free to ask.

 

Regards

Theo

0 Likes
Message 11 of 25

Brian.Price
Advocate
Advocate

The form I use is in the drawing file not any of the models. We use a variety of title blocks so each one is in a parameter to select the one you want in the form. We also have a couple different locations and types of parts lists, which are also selectable in the form. I have a parameter that determines if you are placing views manually or if it generates preset views. I then saved the form and suppressed rule to our new drawing template so it is available on all new drawings.

I am currently stalled out on getting ilogic to run through the BOM and add the sheets, views per item in the BOM automatically.

0 Likes
Message 12 of 25

Anonymous
Not applicable

Hi Brain,

 

I work with @tjvz85 and he asked me to help out on this. 

 

I had a look at your code and it's quite different to our setup. From what I gather, you run your form from the drawing file, correct? Your issue lies here.

selectedfile = oFileDlg.FileName

I think this must be "oFileDlg.FullFileName" name. This is passed to 

Dim oModelName As String = (selectedfile)

 and then to 

oModel = oDocs.Open(oModelName, False)

This line requires a full file path to be passed into "oModelName", which isn't the case.

And finally on to 

oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint1, oViewScale, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "Default")

 

Let me know if this solves your problem, otherwise I have a few suggestions of ways you can debug your code.

0 Likes
Message 13 of 25

Brian.Price
Advocate
Advocate

Thanks for the info on the filepath code. The issue with mine is that I want it to run through all the items in the Structured BOM, get their file path then create the drawing using what parameters I have selected in the form.

I typically have 50-100 items in the bom that need a detailed drawing. How do I go about getting the file path from one, create it's drawing then go to the next item and do the same?

0 Likes
Message 14 of 25

Anonymous
Not applicable

You can use something like this:

 

' Get the active assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
' Get all of the referenced documents.
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments

' Iterate through the list of documents.
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs

       'Perform all drawing functions. I have set this up so that I call a different function depending on what the part is

       'Before creating anything here. Make sure the files are being brought up correctly

       MsgBox(oRefDoc.FullFileName.ToString) 'This will display the files as you go through the assembly

      'This code also needs to either be run from the relevant assembly or open the assembly and set it as active

Next

0 Likes
Message 15 of 25

WCrihfield
Mentor
Mentor

Do you plan to save the new drawing document in the same directory, and with the same file name (with the IDW extension) as the model file found within the BOM row?

Is the Form you mentioned a Global Form, or is it a local Form saved within the main assembly file?

I assume you will want to run this code from the open main assembly, instead of the drawing of the main assembly, right?  What kind of Parameters are you working with?  Are they all UserParameters?  Or are some ModelParameters, ReferenceParameters, or in a Custom Group of Parameters?  Are all the Parameters within the main assembly, or do you need to find parameters within the individual model files (model from the BOM row)?  Do you need to do anything with the iProperties of either the main assembly, or any of the model files within?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 16 of 25

WCrihfield
Mentor
Mentor

Just a tip @Anonymous .

Depending what you're doing, I agree that going through the BOM to get Documents is likely not the mose efficient way of doing it, but using the AllReferencedDocuments method can have its own snags.  It is possible that not all Documents within AllReferencedDocuments are going to be native Inventor model documents.  The Items within it are viewed as "_Document" instead of "Document" because of this, so you should almost always check DocumentType of each before use, depending on what you're wanting to do with them.  A slightly better route might be looping through Assembly.Definition.Occurrences, then Occurrence.ReferencedDocumentDescriptor.RefrencedDocument.FullFileName.  You could also check if the Occurrence is Visible or Active within the current DesignViewRepresentation, or LevelOfDetail, before proceeding, using this method.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 17 of 25

WCrihfield
Mentor
Mentor

Here would be a short iLogic code snippet to get you started getting the FullFileName of the documents for each row of your main assembly's BOM.  I would suggest making this an external iLogic rule, then just make sure the main assembly is open and active when you run it.

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MessageBox.Show("THIS RULE '" & iLogicVb.RuleName & "' ONLY WORKS FOR ASSEMBLY DOCUMENTS.", "WRONG DOCUMENT TYPE", MessageBoxButtons.OK, MessageBoxIcon.Stop)
	Return
End If

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oBOM As BOM = oADef.BOM
oBOM.StructuredViewEnabled = True
'Dim oBOMView As BOMView
For Each oBOMView As BOMView In oBOM.BOMViews
	If oBOMView.ViewType = BOMViewTypeEnum.kStructuredBOMViewType Then
		For Each oRow As BOMRow In oBOMView.BOMRows
			Dim oDoc1 As Document = oRow.ComponentDefinitions.Item(1).Document
			Dim oPathAndName As String = oDoc1.FullFileName
			MsgBox("FullFileName of Item #" & oRow.ItemNumber & " is:" & vbNewLine &
			oPathAndName)
		Next
	End If
Next

 

I might be able to fill in a lot more with answers to my previous questions.

I hope this helps.
If this solves your problem, or answers your questions, please click 'Accept As Solution".
Or, if this helps you reach your goal, please click 'LIKES" 👍.

 

Also, if you're interested, here are a few of the 'Ideas' I'd like to get implemented.
If you agree with any of them, please vote for them.

  • MessageBox, InputBox, and InputListBox Size & Format Options Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 18 of 25

Brian.Price
Advocate
Advocate

I start by adding a base view of the main assembly to the first sheet of the drawing package, and place a parts list, title block, border, etc. 

The form is saved on our .dwg template and is always available for the drawing. It's not required to use but those that do see a increase in accuracy and speed.

I would think I want to run this from the drawing not the model using the part list from the first page to retrieve the file path locations of each bom item.

 

These are the current parameters:

Title Block (several options depending on what we are modeling)

Border(depends on location of project and legal information)

Parts list style (user preference depending on drawing layout style)

Prompted entries for the title block

Auto placement of views or manual

Scale of views

automatic center lines

Dim Styles

 

There aren't any parameters required from the model, everything goes through the drawing.

 

 

 

0 Likes
Message 19 of 25

WCrihfield
Mentor
Mentor

OK. So, when you run this requested code, you will have already created a drawing, used your Form, handled all the interactions with the form, and have a PartsList in place.  I can work with that.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 20 of 25

WCrihfield
Mentor
Mentor

Unfortunately, I'm not able to get the FullFileName (with path) of the file associated with each row of the PartsList, like I can with the BOM.  I can get the FileName with extension (if that column is within the PartsList), but it doesn't show the Path, so unless all Items are located in the same folder, or in predictably named sub-folders of the folder where the main assembly is located, I wouldn't be able to generate drawings for them.  If any of the PartsListColumns are setup to display FileProperties, I can get the PropertySetID string and the PropertyID Integer, but that doesn't identify the actual file's path either.  Below is the code I tested this idea with.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MessageBox.Show("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.", "WRONG DOCUMENT TYPE", MessageBoxButtons.OK, MessageBoxIcon.Stop)
	Return
End If

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oPList As PartsList = oDDoc.Sheets.Item(1).PartsLists.Item(1)
Dim oFileNameCol As Integer
Dim oPropSetID As String
Dim oPropID As Integer
For i As Integer = 1 To oPList.PartsListColumns.Count
	If oPList.PartsListColumns.Item(i).PropertyType = PropertyTypeEnum.kFilenamePartsListProperty Then
		oFileNameCol = i
	End If
	If oPList.PartsListColumns.Item(i).PropertyType = PropertyTypeEnum.kFileProperty Then
		oPList.PartsListColumns.Item(i).GetFilePropertyId(oPropSetID, oPropID)
		MsgBox("oPropSetID = " & oPropSetID & vbNewLine &
		"PropID = " & oPropIO)
	End If
	i = i + 1
Next
Dim oItemFileName As String
For Each oRow As PartsListRow In oPList.PartsListRows
	oItemFileName = oRow.Item(oFileNameCol).Value
	MsgBox("FileName = " & vbNewLine &
	oItemFileName)
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes