hooked on programming - hiding and arraying parts

hooked on programming - hiding and arraying parts

Anonymous
Not applicable
1,051 Views
14 Replies
Message 1 of 15

hooked on programming - hiding and arraying parts

Anonymous
Not applicable

See below... I have the parts hiding from my spreadsheet, and I have array working, but I can't figure out how to array the part I just hid, which is probably the best way to do this.

 

I need to find a book or resource so I better understand these commands and variables, esp. those that apply specifically to running the native inventor tools, vs. just trying different combinations to see what works.

 

TIA for any assistance

 

James

 

 



Sub BOOM2() Dim oApp As Application Set oApp = ThisApplication Dim oDoc As Document Set oDoc = oApp.ActiveDocument ' Check if user is in part or assembly If oDoc Is Nothing Or TypeOf oDoc Is DrawingDocument Then Exit Sub End If Dim oCompDef As ComponentDefinition ' Get component definition Set oCompDef = oDoc.ComponentDefinition Dim oAssyDef As AssemblyComponentDefinition Set oAssyDef = oDoc.ComponentDefinition 'don't need this? 'Dim oParams As Parameters 'Dim oParam As Parameter ' Get parameters object 'Set oParams = oCompDef.Parameters ' define wsheet variable, etc Dim exapp As Excel.Application Dim wsheet As Excel.WorkSheet Dim part As Excel.Range Dim parts As Excel.Range 'need qty as an integer for now 'Dim qty As Excel.Range Dim qty As Integer Dim qtys As Excel.Range 'could just put "1" straight in, but an artifact of the old code: Dim no_x_rect As Integer no_x_rect = 1 Dim XAxis As WorkAxis Dim YAxis As WorkAxis Dim Zaxis As WorkAxis With oAssyDef Set XAxis = .WorkAxes(1) Set YAxis = .WorkAxes(2) Set Zaxis = .WorkAxes(3) End With 'Dim hider As String Dim pt(2) As Double 'Dim qt(2) As Double Set exapp = CreateObject("Excel.Application") 'this actually works to set the path: Dim sFilePath sFilePath = exapp.GetOpenFilename(FileFilter:="Excel Files (*.xls*),*.xls*", Title:="Select Work Order") 'pop open excel visibly so I know I have the right file and workbook open (for now...) exapp.Visible = True exapp.Workbooks.Open sFilePath Set wsheet = exapp.ActiveSheet 'Selecting ranges - this will get smarter Set parts = wsheet.Range("E2:E87") Set qtys = wsheet.Range("C2:C87") 'temporarily set quantity to get array working automatically qty = 10 parts.Select pt(0) = 0: pt(1) = 0: pt(2) = 0 For Each part In parts 'trying to concatonate, still using a formula in excel to process "K123456" into "123456*". 'hider = "part" & "*" 'this works Call SetVisibility(oDoc.ComponentDefinition.Occurrences, part.Text, False) 'very possible that wildcards will not work to select items for pattern. Also the transientobjects, etc... does not select the 'correct part to array. It's currently part.Text, so the call function needs to be modified so it just arrays what is already set. 'Dim objCol As ObjectCollection ' Set objCol = ThisApplication.TransientObjects.CreateObjectCollection 'objCol.Add oAssyDef.Occurrences.Item(1) Call oAssyDef.OccurrencePatterns.AddRectangularPattern(part.Text, XAxis, True, 10, no_x_rect, YAxis, True, 10, qty) 'I don't understand what this does, seems to be incrementing the for loop to the next cell in the range I created above. 'pt(0) becomes pt(1), 1 becomes 2, and it steps along like that. But how does it know what "pt" is, I did not define it. pt(0) = pt(0) + 1 pt(1) = pt(1) + 1 Next part ' This is a second loop that would pattern random stuff to impressive useless effect... I am trying to incorporate it above. 'qtys.Select 'qt(0) = 0: qt(1) = 0: qt(2) = 0 'For Each qty In qtys 'makes a collection of whatever is in the assembly - I think the first couple of things. Maybe 0, 1. I think changing (1) to (2) 'lets you pick the third item and pattern it, yeah... 'Dim objCol As ObjectCollection ' Set objCol = ThisApplication.TransientObjects.CreateObjectCollection 'objCol.Add oAssyDef.Occurrences.Item(1) 'Call oAssyDef.OccurrencePatterns.AddRectangularPattern(part.Text, XAxis, True, 10, no_x_rect, YAxis, True, 10, qty) 'qt(0) = qt(0) + 1 'qt(1) = qt(1) + 1 'Next qty End Sub ' I believe I need to add what is below in above inside the loop to find subassemblies below the top level to hide or pattern. Private Sub SetVisibility(Occurrences As ComponentOccurrences, SearchName As String, VisibilityOn As Boolean) ' Iterate through each of the occurrences in the collection provided. Dim oOccurrence As ComponentOccurrence For Each oOccurrence In Occurrences ' Check to see if the occurrence name matches the search name. ' The strings are converted to upper case to remove context sensitivity. If UCase(oOccurrence.Name) Like UCase(SearchName) Then ' Check to see if the visibility is different than the specified visiblity. If oOccurrence.Visible <> VisibilityOn Then ' Set the visibility of the occurrence. oOccurrence.Visible = VisibilityOn End If End If ' If this occurrence is a subassembly, recursively call this ' function to traverse through the subassembly. If oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then Call SetVisibility(oOccurrence.SubOccurrences, SearchName, VisibilityOn) End If Next End Sub
0 Likes
1,052 Views
14 Replies
Replies (14)
Message 2 of 15

MechMachineMan
Advisor
Advisor

Couple questions on your approach here:

 

1) Do you have a reason for using an open file and then not deleting the invisible occurrences?

 - It might be easier to just add new occurrences to a new assembly file rather than deal with visibility.

 

2) Given that you are using visibility, are you exporting parts lists filtered by visibility, or simply just a "Parts Only" list - ie; are you handling the creation/consumption of parts involved with assemblies?

 

3) Is there a workflow reason for using patterns?

- If done by macros, inserting additional occurrences is just as easy.

- If it's for ease of deletion/quantity changes, each part could just be put in it's own folder instead

 

4) What exactly is the data in the excel sheet? Is it part numbers, or occurrence names or file names? Does it include all 3 of those?


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 15

MechMachineMan
Advisor
Advisor

As a sample or something too look at how someone else might write the code, here is what I have kind of refactored it into.

 

This version likely has bugs in it, but the layout is more along what I would recommend using:

 

 

Sub MainHideAndPattern()
    'Use sub main to set up main variables needed to drive everything
    'Call subs from here to make it more legible/easier to debug.
    'Using Import as a byRef instead of as a function just to possibly leave room
    '     for pulling additional info from the spreadsheet within the same function
    '     all while skipping having to use global variables

    Dim oApp As Application
    Set oApp = ThisApplication
    
    Dim oDoc As Document
    Set oDoc = oApp.ActiveDocument
    
    ' Check if user is in part or assembly
    If oDoc Is Nothing Or TypeOf oDoc Is DrawingDocument Then
        Exit Sub
    End If
    
    Dim parts(,) As String
    
    Call ImportDataFromExcel(parts, "D2:E87")

    Dim oTransaction As Transaction
    Set oTransaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "MacroHideAndPattern")

    On Error Resume Next
   
    Call HideAndPatternArrayComponents(oDoc, parts)
If Err.Number <> 0 Then MsgBox("Error Encountered: " & Err.Number & vblf & _ Err.Source & vblf & _ Err.Description & _ vblf & _ "Abortings!") oTransaction.Abort Else oTransaction.End MsgBox("Rule Complete!") End if End Sub Private Sub ImportDataFromExcel(ByRef oArr1(,) As String, ByVal oRange1 As String) 'This procedure requires the project reference: Microsoft object library 'Create a new excel instance 'Grab info in the range. 'Release excel as it is no longer useful Dim exapp As Excel.Application Dim wsheet As Excel.WorkSheet Set exapp = CreateObject("Excel.Application") Dim sFilePath sFilePath = exapp.GetOpenFilename(FileFilter:="Excel Files (*.xls*),*.xls*", Title:="Select Work Order") exapp.Visible = False Set exwb = exapp.Workbooks.Open sFilePath Set exsheet = exwb.Worksheets(1) '??? = Length of range in base 0 'ReDim oArr1(0 to 1, 0 to ???) oArr1 = exsheet.Range(oRange1) exapp.quit Set exapp = Nothing End Sub Private Sub HideAndPatternArrayComponents(oDoc As Document, oArr(,) As Variant) 'Grab the assembly doc axes for use in the pattern 'Iterate through the array; ' Set the visiblity of the occurrences as per the toggle ' Pattern the occurrences to get the right number of them in the BOM ' Note: this is probably not the best workthrough, unless there is additional specific requirements by your client Dim oAssyDef As AssemblyComponentDefinition Set oAssyDef = oDoc.ComponentDefinition Dim XAxis As WorkAxis Set XAxis = oAssyDef.WorkAxes(1) For j = LBound(oArr, 2) To UBound(oArr, 2) Call SetVisibility(oAssyDef.Occurrences, oArr(0,j), False) 'AddRectangularPattern(objcollParentComponents, objColumnEntity, boolColumnEntityNaturalDirection, varColumnOffset, varColumnCount, _ ' [varRowEntity], [boolRowEntityNaturalDirection], [varRowOffset], [varRowCount] ) Call oAssyDef.OccurrencePatterns.AddRectangularPattern(oArr(0,j), XAxis, True, 10, oArr(1,j)) Next End Sub Private Sub SetVisibility(Occurrences As ComponentOccurrences, SearchName As String, VisibilityOn As Boolean) ' Check to see if the occurrence name matches the search name. ' The strings are converted to upper case to remove context sensitivity. ' Check to see if the visibility is different than the specified visiblity. ' Set the visibility of the occurrence. ' If this occurrence is a subassembly, recursively call this ' function to traverse through the subassembly. Dim oOccurrence As ComponentOccurrence For Each oOccurrence In Occurrences If UCase(oOccurrence.Name) Like UCase(SearchName) Then If oOccurrence.Visible <> VisibilityOn Then oOccurrence.Visible = VisibilityOn End If End If If oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then Call SetVisibility(oOccurrence.SubOccurrences, SearchName, VisibilityOn) End If Next End Sub

 

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 4 of 15

Anonymous
Not applicable

Couple questions on your approach here:

 

1) Do you have a reason for using an open file and then not deleting the invisible occurrences?

 - It might be easier to just add new occurrences to a new assembly file rather than deal with visibility.

 

For sure!  The reason I'm doing this now is as an artifact of the way we do it by hand.   Ultimately what I'd like to do is delete the occurrences that do not have a matching part number/filename in my work order, as the way that we control revisions and current parts is by their presence or absence from the "part family" .iam.  It's the starting point for all orders.   Visibility may be a decent path to this as I would still hide the parts in the order, then have the code select all visible and delete those, then show all, update the BOM quantities (we run a bit of code to do this now, to get accurate part counts,) and export the structured BOM to excel.

 

2) Given that you are using visibility, are you exporting parts lists filtered by visibility, or simply just a "Parts Only" list - ie; are you handling the creation/consumption of parts involved with assemblies?

 

Exporting the entire BOM structure - this gives my aftermarket android/google docs based spreadsheet exactly what it wants to populate the qty's in my application for the shop floor.

 

3) Is there a workflow reason for using patterns?

- If done by macros, inserting additional occurrences is just as easy.

- If it's for ease of deletion/quantity changes, each part could just be put in it's own folder instead

 

Just using patterns because that's what we do manually, and it's a visual way of seeing how many parts are in the order.   We could certainly do it by inserting occurrences somehow, copying existing or what have you.   Currently I do unselect parts of out a pattern with qty x to put them into a pattern of qty y if I need to adjust things. 

 

4) What exactly is the data in the excel sheet? Is it part numbers, or occurrence names or file names? Does it include all 3 of those?

 

It's all of these things and more, columns for part number and the required amount are what is important.   The file names are not in it, but the file name we use always includes the part number, and usually a version: "127335B" is rev b of 127335.   Only the current versions are in the parts family, so when I'm running my code now I just have it search for 127335* and it finds all occurrences.  

 

 
0 Likes
Message 5 of 15

MechMachineMan
Advisor
Advisor

How do you currently handle parts that are a sub-part of an assembly, and also part of a weldment?

 

Wldm-A

 - PartA

 - PartB

Part B

 

ie; Customer wants 1 Wldm-A and does not need part B. 

 

In your top level, do you just have qtys of every part placed and mostly just reduce the quantities to 0, so that you just deal with the components in the top level assembly, and just order all of the parts required for Wldm-A separate/entirely as children of A?

 

Is there ever a need to excluded a part (i.e.; if you had PartA in stock already and didn't need to order another to make Wldm-A?)


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 6 of 15

Anonymous
Not applicable

How do you currently handle parts that are a sub-part of an assembly, and also part of a weldment?

 

Wldm-A

 - PartA

 - PartB

Part B

 

ie; Customer wants 1 Wldm-A and does not need part B. 

 

 

This doesn't seem to happen - the assemblies are pretty clean and we don't have repeating parts further up the tree - everything is as flat as possible.  Most parts that the code finds are assemblies - as there is the fabricated part and a flat pattern adjacent to one another since it's all sheetmetal.

 

There is one circumstance where you've got this:

 

Assy A

- Assy AA

- Assy AB

- Assy AC

 

Normally, Assy A is ordered complete, but the customer has taken to ordering Assy AB only.   This seems like it would still sort itself out using the code as defined, I just don't have a firm grip on how it's finding the parts down inside assembly A.  It's a separate public sub.  You're going to get frustrated with my lack of know how!!  Like I've said, I think in another week or two I'll get a better handle on things, I'm doing a lot of production stuff in series with this programming.

 

 

 

In your top level, do you just have qtys of every part placed and mostly just reduce the quantities to 0, so that you just deal with the components in the top level assembly, and just order all of the parts required for Wldm-Aseparate/entirely as children of A?

 

Yes, usually - see above.  I don't need to reduce the quantities to zero as it kind of works backwards - our app processes the top level assemblies as needing no cutting, braking, etc...  and directs the floor to produce the right amount of each subassembly part.   I guess since we do one part one drawing, it's all in the parts, from routing, to amounts, etc.   What I need to do is a screencap video showing how this all works, would make it transparent.  I could share my screen - none of this tech is proprietary but it is such a nice system I don't think my boss would mind showing it off.

 

Is there ever a need to excluded a part (i.e.; if you had PartA in stock already and didn't need to order another to make Wldm-A?)

yes - this is handled by one guy's brain - he comes in and says we have PartA, and I manually reduce the quantity to zero in the spreadsheet where I'm pasting my BOM data.  I'm sure we'll get a little better system in the future, this fellow has a pretty heavy work load.
 
 
An artifact of my BOM update code is this, let's say I have two assemblies in an order:
 

 

Assy A

- Assy AA

- Assy AB

- Assy AC

 

Assy B

- Assy AX

- Assy AB

- Assy AZ

 

run the code, and the output has the cumulative result for assembly AB in the order in each Assy AB line: ie: in order to get it correct I delete the Assy AB line out of Assy B before I paste the BOM into the spreadsheet!

 
 
 
0 Likes
Message 7 of 15

MechMachineMan
Advisor
Advisor

Hmmm. Interesting.

 

Why I was asking is because if you have all order-able components in the top level assembly, and just reduce quantities to zero, it kind of handles this.

 

Like if AB can be ordered on it's own and it's parent A can be ordered, have them both in the top level.

 

If only it's parent A is ordered, you can delete the AB that's in there on it's own and your structure for A will be fine.

 

If they want AB and an additional A, you leave the quantities from the top as 1 and 1 each.

 

If only AB is ordered, you can delete parent A, but still have a quantity of AB preserved, so it's maybe a simpler way to handle any part that can be ordered on it's own, without having to maneuver through the tree and delete all sibling components of AB and promote AB to the top level.

 

 

I had also established a BOM qty reduction system a couple months ago that handles the reducing of quantities, but it is definitely not fun! Especially when you start having multiple parents the QTY could be reduced from and then planning it out so that the missing part arrives in time for the last location it's needed. 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 8 of 15

Anonymous
Not applicable

Heh, that is a good point, why not just copy (drag out of the browser into the 3d space) the subassembly that is getting ordered into the top level, and leave it there, as the customer wants to order each of these child assemblies.  This is what we're doing by hand, anyway!  Could have these child assemblies in a folder, if we wanted, and in a separate group in space.   These categorical parent assemblies only exist because these parts were historically ordered as a group... with a part number.

 

 

How are we handling quantities, ie: reducing them to zero - are we talking about exported BOM manipulation outside of inventor?  There are a lot of ways to crack this nut, I agree.

 

I'd have to see your BOM reduction system, having trouble picturing it - as for the missing part, you mean in real life during production?

 

 

Semi-related: Do you like going to football games?

 

 

 

0 Likes
Message 9 of 15

MechMachineMan
Advisor
Advisor

I do not mind them! Going to the one this weekend with a friend from out of town.

 

 

I was thinking some more, and seeing as you create a new "Parts File" for each order anyways, might just be easiest to have a master file with all of the parts in (regardless of level) and just have the code create a new assembly file and place new occurrences of everything it needs in it, seeing as when you open the master file, inventor will have references to all of the documents anyways, and then it saves you a step of having to create the parts file on your own.

 

The other option would be to iterate through and work with the top level, and for each part, either change the qty or remove the occurrence all together.

 

When I get some time I could probably whip up something along the lines of the new doc creation. Shouldn't be too, too difficult.

 

Do you have any preference for whether the generation is run from excel (ie; copy and paste your table into a macro excel file and hit a button to run the generation/open the new file) or would you rather it be run from the master assembly in inventor?

 

Also, do you plan on using a "master form" and inputting quantities/part numbers fresh every time, or is the list created and saved to a specific project folder each time, or are all of the order lists save to the same folder? Or how do you have this working?

-- I ask because I could probably use a listbox or make an auto-navigate to the excel file to save some extra clicking.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 10 of 15

Anonymous
Not applicable

I was thinking some more, and seeing as you create a new "Parts File" for each order anyways, might just be easiest to have a master file with all of the parts in (regardless of level) and just have the code create a new assembly file and place new occurrences of everything it needs in it, seeing as when you open the master file, inventor will have references to all of the documents anyways, and then it saves you a step of having to create the parts file on your own.

 

I create a new parts file by opening one with all of the parts, file save as, I think you know this - but I'll send you a screencast link and then you can see for sure.  If we do create a master file, does it need to open to create this assembly?  Some of my parts family assemblies take a while to open up...  Opening up a behemoth like that could take a while any time you want to make any changes - but only at the top level, I guess.

 

 

The other option would be to iterate through and work with the top level, and for each part, either change the qty or remove the occurrence all together.

 

When you talk about changing quantities, are you talking about arrays or are we just adding parts to the assembly in some other way?

 

 

When I get some time I could probably whip up something along the lines of the new doc creation. Shouldn't be too, too difficult.

 

No hurry, I've caught up with my orders after a month of hustling!  This will just make it so much more accurate in the future.  I did make the odd error - one time I fat fingered my array and patterned in the x and the y, we made 2x as many parts.

 

Do you have any preference for whether the generation is run from excel (ie; copy and paste your table into a macro excel file and hit a button to run the generation/open the new file) or would you rather it be run from the master assembly in inventor?

 

The customer with the largest work orders has a website where I can have them exported and downloaded as excel, what I do now is a few edits, then it's ready for the code I have to start running, all I do is select the .xls when prompted.  I'd have to customize this - my idea was to have a drop down, select the client, then click on the .xls and click open - that way the code runs properly and imports the columns properly for part and quantity.

 

Also, do you plan on using a "master form" and inputting quantities/part numbers fresh every time, or is the list created and saved to a specific project folder each time, or are all of the order lists save to the same folder? Or how do you have this working?

 

I think I answered this above - We're getting the quantities and the part #'s fresh every time, directly from the customer order!   This is why it's so fast and accurate.

 

-- I ask because I could probably use a listbox or make an auto-navigate to the excel file to save some extra clicking.

 

Yep.  See my screencast to see what's up.

James

 

 

0 Likes
Message 11 of 15

Anonymous
Not applicable

Been sleeping on this for a while...

 

I think I can make one large assembly, with all of the customer part families sub assemblies inside of it.  If required, have every part arrayed in their own pattern with a qty of 1 on the y axis.  I didn't realize you could make an array of 1 part, (can't go to qty 0....)


The .iam's do need to exist, with the proper parts in the proper quantities, as parts are often an assembly with an accompanying flat pattern sheetmetal part with material properties matching the raw material - the nesting software picks up the flat pattern and the length of pipe required to do the job (for instance) is given by the nesting software.... if the stuff actually is flat it doesn't need an adjacent flat pattern part, it just gets nested.

 

 

 

0 Likes
Message 12 of 15

MechMachineMan
Advisor
Advisor

I've kind of got either end of this done; just need to tie it together.

 

Trying running this macro below with a test source assembly open, and change the array in the last function to match your part numbers/desired quantities and let me know if this sort of setup works for you.

 

This is in vba, not vba, so it needs to be run from the vba editor environment.

 

Private oArr As Variant
Private invApp As Inventor.Application
Private oMissingDocs As String

Sub Main()
    Set invApp = ThisApplication
    
    Dim oSourceDoc As Document
    Set oSourceDoc = invApp.ActiveDocument
    'Dim oSourceDoc As Document = invApp.Documents.Open()
    Dim oNewDoc As Document
    Set oNewDoc = invApp.Documents.Add(12291) '12291 = ObjectTypeEnum.kAssemblyDocumentObject
    
'Load
    oArr = LoadArrayFromHardcode()
    
'Process
    oMissingDocs = ""
    Call PlaceOccsFromArr(oSourceDoc, oNewDoc, oArr)
    
    If oMissingDocs <> "" Then
        MsgBox oMissingDocs
    Else
        MsgBox "Rule complete!"
    End If
    
Set invApp = Nothing End Sub Sub PlaceOccsFromArr(oSourceDoc As Document, oNewDoc As Document, oArr As Variant) Dim oPartNumber As String Dim oQty As Integer Dim oSubDoc As Document Dim oStartXLoc As Double oStartXLoc = 0 Dim oFound As Boolean For j = LBound(oArr, 1) To UBound(oArr, 1) Set oSubDoc = Nothing oFound = False oPartNumber = oArr(j, 0) oQty = CInt(oArr(j, 1)) Dim oOpenDoc As Document For Each oOpenDoc In oSourceDoc.AllReferencedDocuments If oPartNumber Like oOpenDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value & "*" Then Set oSubDoc = invApp.Documents.ItemByName(oOpenDoc.FullFileName) oFound = True Exit For End If Next If oFound = False Then MsgBox ("Open Doc Matching Part Number in Array not found!" & vbLf & "Skipping!") oMissingDocs = oMissingDocs & vbLf & oPartNumber GoTo NextFor End If Call PlaceXDocs(oNewDoc, oSubDoc, oStartXLoc, oQty) NextFor: Next End Sub Sub PlaceXDocs(oNewDoc As Document, oSubDoc As Document, ByRef oStartXLoc As Double, oQty As Integer) Set oNewDocCD = oNewDoc.ComponentDefinition Set oTG = invApp.TransientGeometry Set oMatrix = oTG.CreateMatrix Dim oHeight As Double Dim oWidth As Double Dim oThickness As Double oHeight = 0 oWidth = 0 oThickness = 0 Call GetDocDimensions(oSubDoc, oHeight, oWidth, oThickness) For j = 1 To oQty Call oMatrix.SetTranslation(oTG.CreateVector(oStartXLoc + oHeight / 2, (j - 1) * oHeight * 1.5, 0)) Call oNewDocCD.Occurrences.Add(oSubDoc.FullFileName, oMatrix) Next oStartXLoc = oStartXLoc + oHeight / 2 End Sub Sub GetDocDimensions(oDoc As Document, ByRef oHeight As Double, ByRef oWidth As Double, ByRef oThickness As Double) Set oRangeBox = oDoc.ComponentDefinition.RangeBox XDif = oRangeBox.MaxPoint.X - oRangeBox.MinPoint.X YDif = oRangeBox.MaxPoint.Y - oRangeBox.MinPoint.Y ZDif = oRangeBox.MaxPoint.Z - oRangeBox.MinPoint.Z oHeight = MaxOfMany(Array(XDif, YDif, ZDif)) oThickness = MinOfMany(Array(XDif, YDif, ZDif)) oWidth = XDif + YDif + ZDif - oHeight - oThickness End Sub Function MaxOfMany(oVars As Variant) oMax = oVars(0) oMin = oVars(0) For Each oVal In oVars If oVal > oMax Then oMax = oVal End If If oVal < oMin Then oMin = oVal End If Next MaxOfMany = oMax End Function Function MinOfMany(oVars As Variant) oMax = oVars(0) oMin = oVars(0) For Each oVal In oVars If oVal > oMax Then oMax = oVal End If If oVal < oMin Then oMin = oVal End If Next MinOfMany = oMin End Function Function LoadArrayFromHardcode() As Variant Dim oArr(2, 1) As String oArr(0, 0) = "020-0105" oArr(0, 1) = "2" oArr(1, 0) = "320-5019" oArr(1, 1) = "1" oArr(2, 0) = "320-5660" oArr(2, 1) = "3" LoadArrayFromHardcode = oArr End Function

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 13 of 15

Anonymous
Not applicable

Came in early this AM to get this going - it runs and FAST!  Behavior is as desired, I might sharpen it up to put each part in its own folder, but not much point to that, you'd still have to consult the BOM to double check quantities.   I see it makes a new assembly, I wonder how it knows what template to use.  Must just pick the first one, or the generic Inventor assembly.  ('12291 = ObjectTypeEnum.kAssemblyDocumentObject.)  I only care because I cannot get this ilogic rule that I use for a custom quantity column to run from global, and I have the rule in a different template.   I may not need this any more with this new code!  Need to do more testing and messing around.

Thanks for this, I feel like I'm (you're) going in a good direction!  The problem is it's now 100% over my head, I'm going to need to figure out some kind of more basic resources to read to get more familiar with VBA.  I feel like I've said this before.

How was the game, did it feel any different in the new stadium?  Nobody lost!

Thanks!


James

0 Likes
Message 14 of 15

MechMachineMan
Advisor
Advisor

 

Game was good; had seen the new stadium previously at the RAMS vs Huskies game, and it's still as awesome as it was then. Nice to be able to get around the whole thing on the concourse.

 

--

 

Yup, it does just default to the generic one, but can be set up to use any file you desire as a template.

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-66A32241-D9C0-4E9D-B6D1-F4A9DA1F69F9

 

That being said, I will still just combine these when I have time. You could also make that macro work for you in the meantime by using excel to concatenate a list of file in the proper format, pasting it over the code, and changing array bounds.

 

After looking at the output, I had thought folders might be overboard as the files can be resorted by name so every occurrence of the same part number is right beside it's sibling anyways. Seemed like just adding extra complexity to put them into folder when the same info can be gathered by the re-sorting the browser nodes.

 

Good to hear that it's working for you so far!

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 15 of 15

Anonymous
Not applicable

I will give it a try pasting in some inputs. : )

I agree re: folders, just more programming.  I will do some more testing, I need to talk to my appsheet programming guy/boss to see why we were running that bom qty ilogic instead of handling things another way and also about some other simplifications I'd like to do now that I'm understanding things better around here. 

 

You already have season tickets for the riders games or are you going a la carte?

 

 

0 Likes