Moldflow Insight Forum
Welcome to Autodesk’s Moldflow Insight Forums. Share your knowledge, ask questions, and explore popular Moldflow Insight topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Question - macro for duplicating studies

3 REPLIES 3
Reply
Message 1 of 4
htr.carneiro
461 Views, 3 Replies

Question - macro for duplicating studies

Hey guys,

 

I'm currently working on a macro that automatically duplicates a study three times; in the end, I want to have four studies, with different names and a few changes in the pack/holding profile.

 

However, I'm stuck in a particular question: is it possible to tell the macro that the study name is variable? Because here's what I'd like the macro to do: from a study named "study_fpw01", the macro would automatically create three new studies named "study_fpw02", "study_fpw03" and "study_fpw04".

 

I've looked into the API Reference and found a few commands that I think it could help me:

 

Boolean  DuplicateStudyByName (String aName)
Boolean  RenameItemByName (String aName, String aType, String aNewName)

 

String  GetFirstStudyName ()

 

I tried to work with this last command, but it can only get the first study name or the next study name. Is there something more specific for this case?

 

Thank you for taking the time to read this.

 

Best regards 

 

3 REPLIES 3
Message 2 of 4
nordhb
in reply to: htr.carneiro

Hi,

as you have the first study, I think this could be a method:

 

Set Project = Synergy.Project()
Project.DuplicateStudyByName2 "study_fpw01", True
Project.RenameItemByName "study_fpw01 (copy)", "Study", "study_fpw02"

Project.DuplicateStudyByName2 "study_fpw01", True
Project.RenameItemByName "study_fpw01 (copy)", "Study", "study_fpw03"

 Hope this helps.

 

Regards,

Berndt



Berndt Nordh
Message 3 of 4
htr.carneiro
in reply to: nordhb

Hello Berndt Nordh,

 

thank you very much for your help.

 

I tried to run your code but it wasn't able to do what I expected. That's because this code does not recognize the name of the first study as a variable. Is there some kind of command that can do this? Because I would like it to work for any study that I might work with in the future.

 

Best Regards,

 

Heitor

Message 4 of 4
nordhb
in reply to: htr.carneiro

Hello Heitor,

a couple of options:

 

You can open the first study by name:

Set Project = Synergy.Project()
Project.OpenItemByName "study_fpw01", "Study"

 
Or open the first study in project, and assuming it holds your first study study_fpw01 :

Set Project=Synergy.Project()
StudyName =Project.GetFirstStudyName()
Project.OpenItemByName StudyName, "Study"


Or, open a study manually (or by script) and get the active study name to use:

Set StudyDoc = Synergy.StudyDoc()
StudyActive = StudyDoc.StudyName '** this is with .sdy
StudyActiveName = left(StudyDoc.StudyName, len(StudyDoc.StudyName)-4) '** this is without .sdy

 

Hope you find that something of above will resolve your script issue.

 

Regards,

Berndt



Berndt Nordh

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

Post to forums  

Autodesk Design & Make Report