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

SAC: Enums and Switches

2 REPLIES 2
Reply
Message 1 of 3
doni49
603 Views, 2 Replies

SAC: Enums and Switches

I've read about the bug in SAC that makes it so that you have to convert your enum to a string (and how to use an if statement to decide what to set it as).  But I wanted to see if I could find an alternative way that didn't involve some long if statement (imagine if your enum has 5-6 options -- good grief).

 

First, I decided to see what would happen if I just converted the enum value directly to a string.  It didn't work exactly as I'd hoped but it did get somewhere.  The end result is that as long as you know the ORDER of the diff options when you're creating your SA, then this'll work.

 

Each item in the enumeration takes on a numeric value beginning with 301.  The first item in the list is 301, the second is 302, the third is 303 and so on.

 

  • So at some point before your switch statement, place a "Define Variable" of type String.  If the name of your input paramater that uses the enum is Test, then the default value of this variable is Test.toString().  I'll assume that your variable name is TestString.
  • Place your Switch and it's expression will be TestString.
  • Each "case" will be 301, 302, 303 etc.

I don't know about anyone else, but I think I'd prefer this over the if statement.

 

I'm attaching my test pkt file in case anyone would like to test this for themselves.

 

In the following screen shot, P1 (the point on the left) has it's code set to the value of TestString1 which is tied to the value of Tst1.  As I change Tst1, that code changes.  The same thing for P2 (the point on the right) execept the code is set to TestString2 which is tied to Tst2.

 

Further testing shows that P4, P5 or P6 only shows up when the proper item in the enum is selected.

 

SACEnumSwitch.png

 

EDIT:  This was done in SAC 2012.

 

 



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

2 REPLIES 2
Message 2 of 3
doni49
in reply to: doni49

Hmmm.  Upon further tinkering, I've found that if you don't need the string for anything other than the switch, you don't even need to create the variable.  In your switch statement, you can put Test1.toString().



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 3 of 3
doni49
in reply to: doni49

I just had a bit of an epiphany about this one.  If the enum's name is Par2 (as it is in this example), set the switch statement to Par2.value.tostring().  Now the switch statement has the text value of the currently selected item in the enum.

 

See the following image.  The pkt file is attached for your reference.  In this test case, the enum has 9 different options.  If you had to do that with if statements, that would get very compicated.

 

EDIT:  Using this method instead of what I previously suggest above, you no longer need to worry about the ORDER of the enum items.

 

SACSwitch.png

 

 



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report