Automating the process of importing a part as a reference to a part file and transfer all properties to iproperties

Automating the process of importing a part as a reference to a part file and transfer all properties to iproperties

pedro.lopezMGBEC
Participant Participant
354 Views
5 Replies
Message 1 of 6

Automating the process of importing a part as a reference to a part file and transfer all properties to iproperties

pedro.lopezMGBEC
Participant
Participant

Hello there, 

I am trying to create a logic rule to automate importing a part as a reference (from Solidege/Solidworks/catia/pro-e) and then importing all the properties to the part file with logic; any ideas will be greatly appreciated. 

I've found this.

' Assuming transfer a custom property named "PartNumber" from Solid Edge to Inventor
Dim importedPart As PartDocument
importedPart = ThisDoc.Document

' Access the custom property from Solid Edge
Dim seProperty As String
seProperty = importedPart.PropertySets.Item("Custom Properties").Item("PartNumber").Value

' Transfer the property to an Inventor custom property
ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties").Add("PartNumber", seProperty)

 

0 Likes
355 Views
5 Replies
Replies (5)
Message 2 of 6

A.Acheson
Mentor
Mentor

Hi @pedro.lopezMGBEC 

When you do this manually what are the steps? If the iproperties are not there allready then there is likely no way to get them other than input them from a user input. 

 

What file extensions are you working with? 

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

pedro.lopezMGBEC
Participant
Participant

The steps manually will be as follow:

Import a file

Select a SolidEdge Part file (.par extension)

Activate the Reference option

Select the Solidedge property model to map

and then click ok

and then save the file as Inventor part fie.

 

Idealy I would like to have this as batch import 

0 Likes
Message 4 of 6

A.Acheson
Mentor
Mentor

Here is an article that runs through the options for importing Anycad Documents. It is written in VBA so you will need to convert the code to whatever your using. 

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

WCrihfield
Mentor
Mentor

Hi @pedro.lopezMGBEC.  Here is a link to the online help page about how to set up the property mapping from non-Inventor files to native Inventor files, when Importing them.  It tells you two ways to access those settings manually, one of which seems to be like a standalone application that works with Inventor, that can be started through the Windows start menu, under your Autodesk stuff.

To Map Properties from Imported CAD Data to Standard Inventor Properties 

It seems like the property copy over part of the import task should be handled automatically for you, once you have those settings set the way you want them.  With that in mind, I would assume that you do not need to include anything special in your code for that portion of the task.

 

Another little detail that may be important to pay attention to in this code process is the difference between the regular ImportedComponentDefinition API object Type, and the ImportedGenericComponentDefinition API object Type, which is a Type that is derived from the other, but has many more properties.  The ImportedComponents collection object offers 3 methods.  One is for adding a new ImportedComponent using what is says is an ImportedComponentDefinition, and the other 2 are for creating new definitions, but both methods say they will return a regular ImportedComponentDefinition.  And the documentation for the ImportedGenericComponentDefinition says that the only natural way to access an object of that Type, is by copying one that already exists.  But as you can see in the 'Mod the Machine' example (and others), we can declare our variable as an ImportedGenericComponentDefinition, then set the value of that variable with the ImportedComponents.CreateDefinition method, which still works because this type is derived from that other type.  But you will most likely want to be using that derived type in order to access/use all of its added methods & properties.  Just wanted to mention that, because derived Types can be confusing to deal with sometimes.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

pedro.lopezMGBEC
Participant
Participant

Hi guys, well based on the info provided by @A.Acheson  (thank you for that though) I cleaned and modified the code from Mode the Machine (thanks to @Adam Nagy as well) the intention is to import small group of files converting them to Inventor after the import but is important to get in the inventor part file all the properties that are in the files that we import.

I attached the code (was working on it but end of the day for me) it work fine from one file importing the file as a reference but Im trying to access a folder capturing the files there and then execute the import for all those files

this is the piece of code for reading the files as you can see I previously add a multivalue parameter in Inventor to check is reading the files

 
 
Imports System.IO
Sub Main
    ' Specify the folder path you want to get the file names from
    Dim folderPath As String = "C:\XFolder"   'In here the path to the folder you want to get the files frt
   
    ' Get an array of file names in the specified folder
    Dim files As String() = Directory.GetFiles(folderPath)                              'Files are now in the array variable files
        MultiValue.List("LIST_NAMES") = files
    For Each File As String In files                                                    ' You can loop through the array to access each file name
         Console.WriteLine(File)
    Next
End Sub
0 Likes