Read ten parameters from every part in an assembly, export to Excel

Read ten parameters from every part in an assembly, export to Excel

Kersh
Contributor Contributor
472 Views
8 Replies
Message 1 of 9

Read ten parameters from every part in an assembly, export to Excel

Kersh
Contributor
Contributor

I'm trying to enter fastener part numbers associated with individual parts into the part files as parameters.

eg, fastern1, fasterner2 .... etc etc. The fasteners have five digit part numbers, ie. a St/St M10x50 bolt would be 04285, so parameter fastener1 may equal 04285, fastener2 may equal 04567 etc etc.

Some fasteners  are used in the shop to put things together (designated 'pick') and some are sent to site for site assembly (designated 'pack'). So i may need more parameters eg, fasterner1_P, fastener2_P' which match the fasterner numbers

Then when these parts are built into an assembly, i'd like to run some ilogic code to read all these fasteners parameters and export them to excel. so two columns, first one is fastener part numbers (04285, 04567 ....) and a second column (pick, pack..)

 

I should add that within the top level assembly, there may be other sub assemblies that also have the same fastener parameters and i need to call al the fasteners into the excel spreadsheet

 

I'm trying to generate an order list of all the fasteners to order for a particular assembly, without having a single fastener model in my assembly, as these just slow models down and take an age to add.

 

Is this possible with ilogic?

Go easy i'm fairly new to ilogic and forms 🙂

0 Likes
473 Views
8 Replies
Replies (8)
Message 2 of 9

dalton98
Collaborator
Collaborator

Hello, welcome to the forms.

 

A bit of a pushback...

I don't like using model parameters to store non-dimension file information. It can get cluttered very quickly. I like to designate the custom i-properties for text and additional information. They can also be accessed through the BOM and/or without having to open the file.

 

Also I'm wondering how you account for parts requiring multiple bolts or parts using bolts from another part.

 

I have no  idea what your models intel, but it seems like it will be difficult to keep track of it this way. 

0 Likes
Message 3 of 9

Kersh
Contributor
Contributor

Thanks,

I'm not against using the i-properties instead of parameters, whatever works right.

The models are parts of a timber drying kiln. Lots of channels, panels and other randon extrusions all bolted together with M10, M12 bolts,washers & nuts and a few rivets. Ideally i'd like to run some i-logic and get a list of the required fasteners for what ever model i have open, so for a single part it may only list a couple of bolts,washers & nuts. But for the larger asemblies it'd list all the fixings required in all the parts that make that assembly. Again fixings are either 'pick' i.e. required to assemble the sub-assembly, or 'pack' required on site for sub assembly. They're split so that we can obtain a list of fasteners that need to go to site.

The bolts that go into the parts i-props would be only the fixings required to hold that part on to the main structure.

So no fixings are really shared.

0 Likes
Message 4 of 9

A.Acheson
Mentor
Mentor

Hi @Kersh 

 

Have you considered instance properties? See help file here. 

You can tag individual occurrences in the assembly and this can then be used for filtering purposes. Fasteners are always difficult because you need to identify the exact ones that are being used which can be time consuming. A sub assembly for pack to site parts could be a good container to correctly quantify the numbers. However you might end up with duplicates if they are allready in the model. If the correct parts get tagged you can then filter the instance property within the partlist to display the correct qtys. 

 

Alternatively if you have time to do a shipping view rep then you can indicate the direct bolts shipping simply by setting visible or not either manually or by code. Then tally them later by view rep filter in the drawing. 

 

I would avoid iproperties and parameters in the model simply because cant work with read only files which many CC fasteners are. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 9

Kersh
Contributor
Contributor

I've had a look and instance properties might work. As I say, I'm not wanting to put any actual fastener models into my assemblies, CC or otherwise. I'd like to just put pseudo fasteners into my parts and pull them out into a packing list (ala Excel) somehow. I'm not sure how thats easyiest done, but I'm keen for any and all ideas 🙂

0 Likes
Message 6 of 9

Jacob__with__a__k
Enthusiast
Enthusiast

Hi!

 

If you are ok with adding a lot of parts but wanna optimise your model I recommend using Virtual Components

they function as a normal parts but without the model so

you can change their BOMstructure with Ilogic

you can also use ilogic to change the quantities of the parts if nessecary

 

Without adding any (virtual) parts you could make a custom parts list with Ilogic and add all components with code

 

as Packing list I would use a normal Parts list exported in excel

as long as all parts/assemblies have the nessecary Iproperties (Part number/stock number/description ezv) it should work fine 

For the "Pick" and "Pack": if you add it as an Ipoperty, you can add it to the same partslist

and you can choose if you filter the list in inventor or in excel, whatever is your preference

 

Happy coding! 

0 Likes
Message 7 of 9

dalton98
Collaborator
Collaborator

Ok, it sounds like you should store this information at the assembly / sub-assembly level. Last question: Did you use the hole feature or just make an extrusion for the bolt holes? If you used the hole feature you can pull information like the hole size and number of holes easily. ex

Dim oDoc As PartDocument = ThisDoc.Document

MessageBox.Show(oDoc.ComponentDefinition.Features.HoleFeatures(1).HoleDiameter.Value / 2.54)

MessageBox.Show(oDoc.ComponentDefinition.Features.HoleFeatures(1).HoleCenterPoints.Count)

 

0 Likes
Message 8 of 9

Kersh
Contributor
Contributor

It's a bit of a mixture to be honest. Some hole wizzard and some extruded holes. 

0 Likes
Message 9 of 9

dalton98
Collaborator
Collaborator

@Kersh Sorry I'm getting back to you late. If your wanting to automate counting the numbers of holes in a given part's surface body it will be very difficult. There are some posts on the  forms attempting to do this Link 

 

What you were talking about in your original post seems do-able, but will be difficult to create and manage. Like I said its easier to store this information at the assembly level.

 

I made this rule that checks for parameters containing "fastener" and adding them to a dictionary to track the parameter values and count.

'store fastener info
Dim dictionary As New Dictionary(Of String, Integer)

Dim oADoc As AssemblyDocument = ThisDoc.Document

Dim oOccs As ComponentOccurrencesEnumerator = oADoc.ComponentDefinition.Occurrences.AllLeafOccurrences

'search all part only components
For Each oOcc As ComponentOccurrence In oOccs
	Dim oPartDef As PartComponentDefinition = oOcc.Definition
	For Each oParam As Inventor.Parameter In oPartDef.Parameters
		If Not Left(oParam.Name, 8) = "fastener" Then Continue For

'add to the dictionary key's value or create a new key
		If Right(oParam.Name, 2) = "_P"
			Try
				dictionary.Item(oParam.Value & "_P") = dictionary.Item(oParam.Value & "_P") + 1
			Catch
				dictionary.Add(oParam.Value & "_P", 1)
			End Try
		Else
			Try
				dictionary.Item(oParam.Value) = dictionary.Item(oParam.Value) + 1
			Catch
				dictionary.Add(oParam.Value, 1)
			End Try
		End If
	Next
Next

'create a template
System.IO.File.Copy("C:\temp\fastenerlist.xlsx", "C:\temp\fastenerlist2.xlsx")
GoExcel.Open("C:\temp\fastenerlist2.xlsx", "Sheet1")

For i = 0 To dictionary.Count - 1
	GoExcel.CellValue("A" & i + 2) = dictionary.Keys(i)
	If Right(dictionary.Keys(i), 2) = "_P"
		GoExcel.CellValue("C" & i + 2) = dictionary.Item(dictionary.Keys(i))
	Else
		GoExcel.CellValue("B" & i + 2) = dictionary.Item(dictionary.Keys(i))
	End If
Next

GoExcel.Save
0 Likes