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: 

File locatieon in parts list.

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
jostroopers
941 Views, 6 Replies

File locatieon in parts list.

I have an assembly that contains various parts.
I export these parts as a step file.
Those step files are written to a specific folder.
'- - - - - - - - - - - - -STEP setup - - - - - - - - - - - -
oPath = "Z: \ Uni_Link \ Import \ Stepfiles"
'get STEP target folder path
oFolder = oPath & "\" & iProperties.Value ("Project", "Stock Number") & "STEP Files"

-----------------------------------------------------------------------------------------
I need this location in my parts list.
That parts list is saved as a csv file.
That csv file is loaded in another program.
That program looks at the folder location where the step files are.
Those step files are then loaded into the program.
Is it possible to get that folder location from each part in the assy in the parts list after i exported the step files.

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
6 REPLIES 6
Message 2 of 7
WCrihfield
in reply to: jostroopers

Is the CSV file exported directly from a PartsList that is placed on a sheet in a drawing document?

Is this CSV file exported before or after the model files are exported to STEP files?

If the CSV files are exported after the model files are exported to STEP, and the CSV files are exported directly from an instance of a PartsList on a sheet, then:

  • Durring your process (or as part of the process) that exports each model file to a STEP file, also write this full path and file name of the resulting STEP file to a custom iProperty of the Inventor side model file.
  • Then if your PartsList is set-up to display that custom iProperty as one of its columns, the drawing document may just need to be updated, so the PartsList is showing the correct data, then you should just be able to export another CSV file from it to overwrite the existing CSV file.

Then later if the models have already been exported, but the paths weren't written to those custom iProperties within the model files, and you want to solve it with code alone, you would have to build and run a script that searches through the target directory for the files with their part numbers, then return the FullFileName of the found files to the custom iProperty.  Hopefully at least the "Stock Number" iProperty is filled in within the model files, so you can use it in the search path, otherwise you may have to start your search in a higher directory, and include sub directories.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7
jostroopers
in reply to: WCrihfield

To answer your first question, the csv will be exported that is placed on a sheet in a Inventor dwg drawing document.

The second answer, the csv will be exported after the step files are exported.

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
Message 4 of 7
WCrihfield
in reply to: jostroopers

I'm still not sure if the custom iProperty already exists in all the referenced documents within the main assembly, or not.  Or if you are expecting a solution that will create this custom iProperty within all those referenced documents.  If you want that custom property created, then in order to supply a value to it, we will have to incorporate a search routine into the solution that searches down through the step file directories for one that has contains something in its file name.  In this solution, I'm assuming this custom property already exists and already contains the needed path of the exported step files.  Let me know if this is not the case.

I've created an iLogic rule you can try.

This rule is designed to be ran while the main assembly file is open and active

  • It immediately tries to open the assembly's drawing
    • It assumes the drawing has the same path & file name (with the ".dwg") file extension
  • It then tries to get the PartsList
    • It assumes this to be the first one found within the drawing.
  • It then finds which column in that parts list is the one with "Step File" as its title, and captures the columns index number for use later.
    • The this label appears different in the two images you attached.
    • In the image appearing to be of the PartsList within the drawing, the column title looks like "Step File" (with a space between the two words).
    • While the other image, which I assumed was from the CSV file, the column title looks like "StepFile" (with no space between the two words).
    • So I am specifying the searching the PartsList for the title "Step File", then later in the code, I'm searching for the custom iProperty with the name "StepFile", assuming the CSV file may be using the custom property's name as the column title.
  • The code then starts to loop through each row of the parts list, and each row is supplied as input, along with the oCol integer found earlier, to the sub which finishes the job of setting the value to the cell of that row, at that columns intersection.

 

  • Then within the sub
    • It attempts to gets the first document being represented by that parts list row
    • It's showing some commented out code that attempts to get the value of the Stock Number property from that document (even though we're not using it in this scenario)
    • It then attempts to get the custom property called "StepFile" (see naming issues above)
    • If the property is found, it gets its value
    • Then puts that value into the supplied parts list row, at the column number supplied.

Here's the code:

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("This rule was designed to run while an Assembly Document is active.",vbOKOnly, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisAssembly.Document
	'open the drawing for this assembly - assuming it has same path and file name as model file (with different file extension)
	Dim oDDoc As DrawingDocument = ThisApplication.Documents.Open(oADoc.FullFileName.Replace(".iam", ".dwg"))
	'Get the PartsList - assuming it is the first PartsList found within the drawing document
	Dim oPList As PartsList
	For Each oSheet As Inventor.Sheet In oDDoc.Sheets
		If oSheet.PartsLists.Count > 0 Then
			oPList = oSheet.PartsLists.Item(1)
		End If
	Next
	Dim oCol As Integer
	For oCol = 1 To oPList.PartsListColumns.Count 
		If oPList.PartsListColumns.Item(oCol).Title = "Step File" Then ' <<<< CHECK THIS NAME >>>>
			Exit For
		End If
	Next
	Dim oRow As PartsListRow
	For Each oRow In oPList.PartsListRows
		SetStepFilePath(oRow, oCol)
	Next
End Sub

Sub SetStepFilePath(ByRef oPLRow As PartsListRow, ByRef oPLCol As Integer)
	'Dim oPartsList As PartsList = oPLRow.Parent
	Dim oDrawingBOMRow As DrawingBOMRow = oPLRow.ReferencedRows.Item(1)
	Dim oBOMRow As BOMRow = oDrawingBOMRow.BOMRow
	Dim oRowDoc As Document = oBOMRow.ComponentDefinitions.Item(1).Document
	Dim oPropSets As PropertySets = oRowDoc.PropertySets
	'Dim oStockNum As String = oPropSets.Item("Design Tracking Properties").Item("Stock Number").Value
'	If oStockNum = vbNullString Then
'		MsgBox("The 'Stock Number' property was empty in the following document:" & vbCrLf & _
'		oRowDoc.FullFileName, vbOKOnly, "Sock Number Missing")
'	End If

	'Check for the custom 'StepFile' property
	Dim oStepFileProp As Inventor.Property
	Try ' <<<<<<  MAKE SURE THE PROPERTY NAME IS SPELLED CORRECTLY   >>>>>>>
		oStepFileProp = oPropSets.Item("Inventor User Defined Properties").Item("StepFile")
		'oStepFileProp = oPropSets.Item("Inventor User Defined Properties").Item("Step File")
	Catch
		MsgBox("The custom property named could not be found in the following document:" & vbCrLf & _
		oRowDoc.FullFileName, vbOKOnly, "Custom Property Not Found")
		Exit Sub
	End Try
	Dim oStepFile As String = oStepFileProp.Value
	oPLRow.Item(oPLCol).Value = oStepFile
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS :light_bulb:and Explore My CONTRIBUTIONS

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 7
jostroopers
in reply to: WCrihfield

I've added the code.
When I run the code I don't get an error.
But the step file location with the step name is not completed in the partslist
I have added my exercise file.
Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
Message 6 of 7
jostroopers
in reply to: WCrihfield

Ok, I have adjusted my parts with correct iproperties.
I have set the StepFile ipropertie in both correctly, my parts and csv file.
I have exported the step files to the location: Z: \ Uni_Link \ Import \ StepFiles \ 202020 STEP Files
Where 202020 is the name of the assy and STEP Files is an addition from the ilogic code.
The name of the assy, 202020, is also written to the iproperty 'Project'.
In the ilogic form the iproperty 'Project' is translated to Verkooporder.

This Project number will change everytime i make a new configuration and will be saved with a new project number.
The name of the step file is the IProperty 'Stock Number' which will be translated to Artikelnr.
The location with the step file name, Z: \ Uni_Link \ Import \ StepFiles \ 202020 STEP Files \ 15000.stp,
I need it in my parts list under the custom ipropertie StepFile.

I placed the location, Z: \ Uni_Link \ Import \ StepFiles,  already in de ipropertie because that is always the same.
When I run the current code the dwg is opened but the iproperty is not completed with the file location and step file number.

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
Message 7 of 7
jostroopers
in reply to: jostroopers

I have created an custom ipropertie, StepFile.

I put the Iporperties i need into that ipropertie.

I also put in the file location who is always the same.

And there, i get the compleet line i need to export to my csv file.

Without using iLogic.

Great.

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....

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

Post to forums  

Autodesk Design & Make Report