Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating CatPart Dimension via Macro

Status
Not open for further replies.

yusf

Structural
May 9, 2006
58
TR
Hi all;

I recorded a macro within Catia and would like to run this macro in batch mode aiming to update the required parameters dynamically..

I need help at this point beacuse when i update my macro and using
"C:\Program Files\Dassault Systemes\B20\win_b64\code\bin\CNEXT.exe" -nowindow -macro -batch ...\MyMacro.catvbs

it doesnt update my model??

can anyone help?


Language="VBSCRIPT"

Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set parameters1 = part1.Parameters
Set length1 = parameters1.Item("Height")
length1.Value = 200.000000
part1.Update
Set parameters2 = part1.Parameters
Set length2 = parameters2.Item("Width")
length2.Value = 100.000000
part1.Update
Set partDocument1 = CATIA.ActiveDocument
partDocument1.Save
End Sub
 
Replies continue below

Recommended for you

Hi

I have a two file in one folder one of which is Beam.CATPart and the other is my macro CATIAHST.catvbs

I am trying the following code using script i attached

"C:\Program Files\Dassault Systemes\B20\win_b64\code\bin\CNEXT.exe" -nowindow -batch -macro C:\Users\SUN\Documents\HS-1580\approaches\nom_1\run__00001\m_1\CATIAHST.catvbs


but CATIA does not invoke as stated any website i searched...

Any idea why my model does not update..

One can try a simple box model and try to model it parametrically can anyone update the box model with its recorded macro in batch mode?

Regards..
 
There are several problems here...

First I would ask myself how CATIA will know what CATPart should be updated?
If there is no CATIA opened, how can I use ActiveDocument?
Do I really need to specify exactly the path to my CNEXT.exe? Answer here is yes if I have different versions or environments....if you have only one, you can use something like bellow
CNEXT.exe -nowindow -batch -macro c:\temp\Update parameters.catvbs

So, I modified your macro and for me is working fine (compare with your code to understand where are the differences). Here you can find a very documented article about this subject.

Code:
Language="VBSCRIPT"
Sub CATMain()

Dim Documents1 
Dim part1 

[COLOR=#CC0000]    Set documents1 = CATIA.Documents
    Set partDocument1 =documents1.Open("c:\temp\Beam.CATPart")
    Set part1 = partDocument1.Part[/color]
    Set parameters1 = part1.Parameters
    Set length1 = parameters1.Item("Height")

length1.Value = 200.000000
part1.Update
Set parameters2 = part1.Parameters
Set length2 = parameters2.Item("Width")
length2.Value = 100.000000
part1.Update
Set partDocument1 = CATIA.ActiveDocument
partDocument1.Save
End Sub



Regards
Fernando

 
Hi thank you very much for your kind and valuable help to me

I would like to give a bit detail and maybe we can a bit modify above Macro by your help

I run the macro via another software via script.bat file in which some send of codes are available and at each ıteration it changes the workıng directory and copy . Catvbs and . CatPart into thıs current workıng dırectory

Now the questıon ıs how to invoke catia at that current dırectory running macro in batch mode and and Tellıng catıa via that macro the catpart you need is that current dırectory....

In Other Words sınce the current dırectory wıll always change "c:\temp\beam.catpart" should also be updated... In my Other Software such unknkwn folder ıs gıven as %path%\beam.part
So how can we assıgn that dynamıc path ın catıa ınstead of. "c:\temp"


 
Not very clear for me, maybe because I'm not a native English speaker...but what I understood is that you need to pass a variable from a file with extension bat to your catvbs. Is not clear for me if you are reading those variables in the bat file from a text file or is a result from another software.

In this case, you can use something like here. Is pretty similar.

Regards
Fernando

 
Hi Fernando;

Let me explain in simpleform without giving detail..



In My current directory:
I have two file
C:\Temp
-Beam.CATPart
-params.catvbs

my software automatically updates my params.catvbs with new dimensions for "Height" and "Width"
and paste above two file into new directories:


C:\Temp\trials_01
-Beam.CATPart
-params.catvbs ( new updated .catvbs file)

Then at second trial my software again updates params.catvbs and copy and paste them into another working directory

C:\Temp\trials_02
-Beam.CATPart
-params.catvbs ( new updated .catvbs file)


.
.
.
.
C:\Temp\trials_09
-Beam.CATPart
-params.catvbs ( new updated .catvbs file)

1.Question :When i run params.catvbs it doesnt update my model..


2.Quesiton
If ı use your modifed code below as you can see above i need to change

"c:\temp" into to see Beam.CATPart in that current folder..
C:\Temp\trials_01
C:\Temp\trials_02
C:\Temp\trials_03
.
.
etc.. to see

Language="VBSCRIPT"
Sub CATMain()

Dim Documents1
Dim part1

Set documents1 = CATIA.Documents
Set partDocument1 =documents1.Open("c:\temp\Beam.CATPart")
Set part1 = partDocument1.Part
Set parameters1 = part1.Parameters
Set length1 = parameters1.Item("Height")

length1.Value = 200.000000
part1.Update
Set parameters2 = part1.Parameters
Set length2 = parameters2.Item("Width")
length2.Value = 100.000000
part1.Update
Set partDocument1 = CATIA.ActiveDocument
partDocument1.Save
End Sub












 
Again, not enough details to decide how to do the task.

Do you first create all those folders? How do you run the bat file? Once after creating all folders or after creation of each folder? Why do you need to save each time the catvbs in the folder? Are you changing the parameters each time with new values? Depending on how you decide to solve the task, maybe you can put all those variables in a text file and read them from there, passing to a single catvbs and not to many. In other words, run once for all situations, with a single bat file, a single catvbs, a single run command for CATIA batch.

Hope you understood what I described and solve your problem.

Regards
Fernando

 
Hi Fernando;
Q:Do you first create all those folders? How do you run the bat file? Once after creating all folders or after creation of each folder? Why do you need to save each time the catvbs in the folder?
Ans:I use another software that runs and does all staff explained above..Therefore it s not my intention to do like that..
Q:Why do you need to save each time the catvbs in the folder?
Ans:Because software copy those two catpart and params.cvbs into same folder and invoke CATIA with

Code:
 "C:\Program Files\Dassault Systemes\B20\win_b64\code\bin\CNEXT.exe" -nowindow -macro -batch %MODEL_PATH%\params.catvbs
<---- this line is for invoking catia and running macro.
and i wait Beam.CATPart to be updated but it doesnt..

%MODEL_PATH% <---this address is known by software but CATIA doesnot know it..

Q:Are you changing the parameters each time with new values?
Ans:Yes Software i use change it, the software performs some structural analysis (finite element analysis) with solid Beam.Catpart so it first gets catvbs and writes into new Height and Width Values...then saves its into run_01 run_02 etc...at each iteration with new updated model..

Finally i get
C:\Temp\trials_01
-Beam.CATPart
-params.catvbs ( new updated .catvbs file)

There must be some way to write some lines into catvbs such that showing the path of .Beam.CATPart

like for example..
Code:
Dim Documents1 
Dim part1 

Set documents1 = CATIA.Documents
[COLOR=#EF2929]Set path=%current directory%[/color]
Set partDocument1 =documents1.Open("[COLOR=#EF2929]%path%[/color]\Beam.CATPart")
Set part1 = partDocument1.Part
Set parameters1 = part1.Parameters
Set length1 = parameters1.Item("Height")

length1.Value = 200.000000
part1.Update
Set parameters2 = part1.Parameters
Set length2 = parameters2.Item("Width")
length2.Value = 100.000000
part1.Update
Set partDocument1 = CATIA.ActiveDocument
partDocument1.Save
End Sub


Any idea..?
 
For example i seached and found a code similar to what i intent to do

path= systempath[:len(systempath)-4]+r"\startup\materials\German\Catalog.CATMaterial"
MatDoc=CATIA.Documents.Open(pfad)

the path must be the working directory of my CATPart...
 
What you found in above post will not help you. Anyway, this is an interesting requirement but, frankly speaking, I would try to find another way to solve it [smile].

Try to test bellow code with CATIA already opened and check for different folders in those conditions you described. I believe you will get correct actions. But....if you use the code in batch mode you will not get it (please check the differences, with CATIA closed and opened).

If you are able to modify the parameters in catvbs with your program, maybe you could modify also the path.

Code:
Language="VBSCRIPT"
Sub CATMain()

Dim sCurPath
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
Msgbox sCurPath

Dim Documents1 
Dim part1 

    Set documents1 = CATIA.Documents
    Set partDocument1 =documents1.Open(sCurPath & "\Beam.CATPart")
    Set part1 = partDocument1.Part
    Set parameters1 = part1.Parameters

Set length1 = parameters1.Item("Height")
length1.Value = 200.000000
part1.Update
Set parameters2 = part1.Parameters
Set length2 = parameters2.Item("Width")
length2.Value = 100.000000
part1.Update
Set partDocument1 = CATIA.ActiveDocument
partDocument1.Save
End Sub





Regards
Fernando

 


And after updating :)

Thank you very much..Maybe it is long way but i have to follow the software's solution steps..

And i really wonder if there is another short ways to updating..

Anyway my problem solved by your help

Thank you again..


 
 http://files.engineering.com/getfile.aspx?folder=7351446a-d673-49fe-8adb-7ae10a740fdb&file=Step_II_Bingooo.jpg
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top