cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Retrieve Model from Feature using VBA API

BF_10197348
7-Bedrock

Retrieve Model from Feature using VBA API

Hello, 

I am currently building a VBA application to automate a few things in my creo daily workflow and unfortunately I am stuck because I am not able to retrieve a model type variable from a componente type feature variable. I am thinking about model descriptors. I can create it but I am struggling trying assign it to the model. The idea is to reach the model by reading the model descriptor present in the correspondent feature variable. 

thank you in advance! 

4 REPLIES 4

Thank you for your question.
I encourage you to bring more details and context to your initial inquiry. This will make it easier for you to receive meaningful help from other Community members.
Regards,
Andra
RPN
17-Peridot
17-Peridot
(To:BF_10197348)

I’m not a VBA guru and not a VBA fan, but:

 

From the reference doc.

 

The important functions for assemblies are those that operate on the components of an assembly. The object IpfcComponentFeat, which is an instance of IpfcFeature is defined for that purpose. Each assembly component is treated as a variety of feature, and the integer identifier of the component is also the feature identifier.

 

Now if your feature in an assembly is from type Component, then …

 

The property IpfcComponentFeat.ModelDescr returns the model descriptor of the component part or subassembly.

 

I don’t understand that the wording is different to Toolkit, but this may part of the VBA game.

 

For the type it can be only Part or Assembly (Sub)


And I would NOT use this property.

The property IpfcComponentFeat.CompType returns the type of the assembly component. The component type identifies the purpose of the component in a manufacturing assembly.

 

You have to ask the solid about the type, if there is no function for this, compare the extension prt vs asm. 

Note: A solid has sub classes like sheet metal, skeleton….


Only my 2 Cents :

 

 

set model [ps_model current]
# Get Component ID's
 set CompIDs [ps_visit type -model $model component]
 foreach CompID $CompIDs         {
  # get component name
  set CompName [ps_assy component_name  -model $model $CompID]
  # get the extension
  set ext [ps_model ext -model $CompName]
  switch $ext {
   PRT        {
      # proceed if Solid parts
    }
   ASM      {
     # proceed if Assemblies
    }
   default {
         error "Unknow extension '$ext' in assy '$model' found"
    }                                           
  }
}

 

 

cko
12-Amethyst
12-Amethyst
(To:BF_10197348)

Hello

Here is the code to get the Creo file name in the working folder. Please note
I created the code using AI.

Dim stringseq As Istringseq
Set stringseq = BaseSession.ListFiles("*.prt", 1, "")

cko
12-Amethyst
12-Amethyst
(To:BF_10197348)

Hello

It may not be the feature you want, but I'm leaving a message because I think it will be a hint
I'll send you a function that checks if the model referenced by the assembly's component is not in the session
(see blog: https://tool-2020.tistory.com/1159)
korealionkk@gmail.com

Announcements


Top Tags