Updating CatPart Dimension via Macro
Updating CatPart Dimension via Macro
(OP)
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
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





RE: Updating CatPart Dimension via Macro
DO you have in your CATIA file those items? Can you upload the test part here?
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Updating CatPart Dimension via Macro
RE: Updating CatPart Dimension via Macro
RE: Updating CatPart Dimension via Macro
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..
RE: Updating CatPart Dimension via Macro
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 --> catvbs
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 SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Updating CatPart Dimension via Macro
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"
RE: Updating CatPart Dimension via Macro
In this case, you can use something like here. Is pretty similar.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Updating CatPart Dimension via Macro
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
RE: Updating CatPart Dimension via Macro
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
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Updating CatPart Dimension via Macro
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
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 --> Script
Any idea..?
RE: Updating CatPart Dimension via Macro
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...
RE: Updating CatPart Dimension via Macro
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 --> catvbs
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 SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Updating CatPart Dimension via Macro
Thank you very much now it works..!!
I put screenshots as how it updated in folder..
RE: Updating CatPart Dimension via Macro
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..