SpaceClaim scripts does not work on Workbench
Hi,
I ran into a problem when integrating SpaceClaim scripts into Workbench scripts. The scripts worked well on SpaceClaim. But when integrating the scripts into Workbench scripts, it crashed. We have found out that the reason could be the syntax "selection = BodySelection.GetActive()". Is there any way to avoid this? Another question would be what should be paid attention to when integrating SpaceClaim scripts on Workbench? Thank you!
Best Answers
-
@M said:
SpaceClaim commands can be sent from WB but you will have to work out the exact logic. If you are using selections then you will have to incorporate that into the script.A simple example to get started with WB to SC scripting. Should build a box.
Reset() import time t1 = time.time() X = 1000 Y = 1000 Z = 1000 Load = 1000 fx = 'fixFace' lx = 'loadFace' cmd = """ P0 = Point.Create(MM(0),MM(0),MM(0)) P1 = Point.Create(MM(%s),MM(%s),MM(%s)) BlockBody.Create(P0,P1) """%(X,Y,Z) myTemplate = GetTemplate(TemplateName="Static Structural",Solver="ANSYS") mySystem = myTemplate.CreateSystem() geometry = mySystem.GetContainer(ComponentName="Geometry") geometry.Edit(IsSpaceClaimGeometry=True) geometry.SendCommand(Language="Python", Command=cmd) geometry.Exit()
Hi M,
Thank you for the explanation and the example of WB scripts. Since I am new to WB scripting, my questions might not be professional.
In the first paragraph of your answer, by having to work out the exact same logic, do you mean using syntaxes compatible within WB?
As for the example you provided, scripts on line 13-15 are related to SpaceClaim, the others are related to WB, right? My understanding is that this example just shows how SpaceClaim scripts are incorporated into WB and is independent on the first paragraph of your answer. Just trying to follow your logic.
0 -
hello zc,
Q1: by logic, I mean if you want to do selections, you will have to be very strict with the formatting since what gets sent from WB to SC has to be in triple quotes and that makes things harder than they should be. The syntax doesn't matter for WB since it just knows you are sending a string to SC. But the string that SC reads has to be perfect (or you are a better coder than I am an can write forgiving scripts).
Q2: the triple quotes are the lines read by SC. That is the baseline model creation. So you can record/journal things in SC and then edit and drop them in the triple quotes to be sent from WB.
You can do a lot of testing a lot quicker by using the ClearAll() (I think) at the beginning of the string sent to SC.0 -
Hello Zc, 'selection = BodySelection.GetActive()' , requires a active selection from the GUI of the SCDM. Since you are passing the script directly from the WB there may not be any active selection to select from thus throwing an error. You may use some Name Selection or the name of the bodies to get the selection. Also, if you can include the error next time in the query that would be helpful to understand the problem
0
Answers
-
SpaceClaim commands can be sent from WB but you will have to work out the exact logic. If you are using selections then you will have to incorporate that into the script.
A simple example to get started with WB to SC scripting. Should build a box.
Reset() import time t1 = time.time() X = 1000 Y = 1000 Z = 1000 Load = 1000 fx = 'fixFace' lx = 'loadFace' cmd = """ P0 = Point.Create(MM(0),MM(0),MM(0)) P1 = Point.Create(MM(%s),MM(%s),MM(%s)) BlockBody.Create(P0,P1) """%(X,Y,Z) myTemplate = GetTemplate(TemplateName="Static Structural",Solver="ANSYS") mySystem = myTemplate.CreateSystem() geometry = mySystem.GetContainer(ComponentName="Geometry") geometry.Edit(IsSpaceClaimGeometry=True) geometry.SendCommand(Language="Python", Command=cmd) geometry.Exit()
0 -
@M said:
hello zc,
Q1: by logic, I mean if you want to do selections, you will have to be very strict with the formatting since what gets sent from WB to SC has to be in triple quotes and that makes things harder than they should be. The syntax doesn't matter for WB since it just knows you are sending a string to SC. But the string that SC reads has to be perfect (or you are a better coder than I am an can write forgiving scripts).
Q2: the triple quotes are the lines read by SC. That is the baseline model creation. So you can record/journal things in SC and then edit and drop them in the triple quotes to be sent from WB.
You can do a lot of testing a lot quicker by using the ClearAll() (I think) at the beginning of the string sent to SC.Hi M,
Thank you for the comments. I can roughly understand how WB interacts with SC via scripts now. I will test my scripts with the method you suggested and see how it works.
0 -
@Abhijith Rajan said:
Hello Zc, 'selection = BodySelection.GetActive()' , requires a active selection from the GUI of the SCDM. Since you are passing the script directly from the WB there may not be any active selection to select from thus throwing an error. You may use some Name Selection or the name of the bodies to get the selection. Also, if you can include the error next time in the query that would be helpful to understand the problemHi Abhijith Rajan,
Thank you for the comments. So it looks like how WB scripts and SCDM scripts operate are a little different. I will try the method you suggested. And I will also attach the error in the query next time.
0