Cancel
Showing results for 
Search instead for 
Did you mean: 

Script to create a new assembly with n new parts

Experimenter
Experimenter

Hello, I'm trying to create a journal in which a new assembly file is created, with any number of blank parts, all placed at the absolute origin with model reference set. 

 

This would be incredibly useful, however I have very limited vb experience so any help is much appreciated!

 

I see it working somewhat as follows:

  1. Run journal - asks for number (n) of desired parts in assembly
  2. Creates and saves new individual parts
  3. Creates new assembly file
  4. Adds parts by selecting 1 through nth parts listed in Recent Parts of Add Component dialogue box
1 REPLY 1

Re: Script to create a new assembly with n new parts

Experimenter
Experimenter

I am assuming when you say "any number of blank parts" you mean new, empty parts?

 

I have coded a similar Python journal recently, to achieve this I would suggest you record a journal of you creating a new assembly. Then record a journal of you doing (assemblies ribbon bar) Create New. 

 

This will give you two journals that while containing some garbage like UNDO marks (at least .py ones do) but they will contain the relevant code for calling each of those functions.

 

Try editing and running the journals manually in NX until you have removed all of the garbage from them.

 

Now you can make these into subroutines in your IDE to call later. Make them use variables for your partname/number.

 

This gives you a framework to create new parts as called by your main code, which will have to generate a basic UI or similar for you to enter your partnames/how many parts you want.

 

Your code should then store the info from your UI in a list and then run through the list and create a new part for each, with the first part being created with your File>New routine and every successive one being created with the Assemblies>Create New routine. Then, at the end you can either save it manually or (again record a journal to get the code for this) save it automatically.

 

I hope that makes sense!