Text string to a field IF/THEN condition

Text string to a field IF/THEN condition

PauloMiranda8553
Participant Participant
950 Views
12 Replies
Message 1 of 13

Text string to a field IF/THEN condition

PauloMiranda8553
Participant
Participant

I need some help here, I'm trying to set a text string to a field that read a 2 characters from the file name. Kinda of read characters 12 and 13, and if content is RD, the value should be RED, if YL, Yellow, GR - Green, and so on. I have 5 or 6 possible values.

The file name is like: X-25-034-A-PE-PGR-.dwg

 

I alread set this, but always get a  "$(IF,??) " error:
$(IF,$(=$(substr,$(getvar,dwgname),12,2)RD),"RED")

 

The IF/THEN is correct?

Can a text string be assigned to the field? Is this the way?

Help will be very apreciated.

 

Thanks to all.

Paulo Miranda

0 Likes
Accepted solutions (1)
951 Views
12 Replies
Replies (12)
Message 2 of 13

Brock_Olly
Collaborator
Collaborator

From chatGPT:

You're on the right track, but the issue comes from how the string comparison is done in AutoCAD fields. The $(IF) function expects a specific format, and the way you're trying to compare the substring isn't quite right.

Here's an improved version of your field expression:

$(IF,$(=,$(substr,$(getvar,dwgname),12,2),RD),RED, $(IF,$(=,$(substr,$(getvar,dwgname),12,2),YL),Yellow, $(IF,$(=,$(substr,$(getvar,dwgname),12,2),GR),Green, Other)))

 

Explanation:

  • $(substr,$(getvar,dwgname),12,2) gets the substring starting from the 12th character and extracts 2 characters.
  • $(=, ...) compares the extracted substring to a specific value (e.g., RD, YL, GR).
  • $(IF, ...) checks if the condition is true. If it is, it returns the first value (e.g., RED). If it's false, it checks the next condition.
  • I've added an Other value at the end for any unmatched cases.

This expression should work, provided the file name is correct and consistent with your pattern. It will check for RD, YL, and GR, and return the corresponding color name.

Message 3 of 13

PauloMiranda8553
Participant
Participant

Thanks for your reply.

The expression don't work, keep the same "$(IF,??) " error.
Now there's something I found... if I replace alphabetic (e.g., RED) for a numeric value (e.g., 01), it works...
So, the problem is there... extracted substring alphabetic/numeric comparation...

Any clue?

0 Likes
Message 4 of 13

paullimapa
Mentor
Mentor

Make any difference if surround the characters with quotes?

$(IF,$(=,$(substr,$(getvar,dwgname),12,2),"RD"),"RED")

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 13

Brock_Olly
Collaborator
Collaborator

If Pauls doesn't work, does this work?

 

$(IF,$(=,$(substr,$(getvar,dwgname),12,2),RD),"RED",$(IF,$(=,$(substr,$(getvar,dwgname),12,2),YL),"Yellow",$(IF,$(=,$(substr,$(getvar,dwgname),12,2),GR),"Green","Other"))))
Message 6 of 13

PauloMiranda8553
Participant
Participant

Nope... 😢😢

0 Likes
Message 7 of 13

PauloMiranda8553
Participant
Participant

No, either way...

So strange...

0 Likes
Message 8 of 13

Brock_Olly
Collaborator
Collaborator

Workaround Approach

  1. Create a field to extract the substring (store it in a hidden attribute or text field):

    $(substr,$(getvar,dwgname),12,2)
    • This extracts the 12th and 13th characters from the drawing name.
  2. Reference that extracted value in a second field for conditional logic:

    $(IF,$(=,$(substr,$(getvar,dwgname),12,2),"RD"),"RED",
    $(IF,$(=,$(substr,$(getvar,dwgname),12,2),"YL"),"YELLOW",
    $(IF,$(=,$(substr,$(getvar,dwgname),12,2),"GR"),"GREEN","OTHER"))))
    • Important: Ensure that "RD", "YL", and "GR" are explicitly treated as strings.
    • If AutoCAD still refuses to recognize it, try inserting the substring field into an attribute or MTEXT first, then referencing it in the condition.

 

Message 9 of 13

Brock_Olly
Collaborator
Collaborator

I'm kind of going in the dark here so if you could upload your DWG or a sample with the field so we can test it out too that'd be nice.

Message 10 of 13

PauloMiranda8553
Participant
Participant

Thank you  my friends, nothing work.
I attached my sample...

The field should read from the file name... but only in the numeric characteres it work.
Thanks.

 

0 Likes
Message 11 of 13

paullimapa
Mentor
Mentor
Accepted solution

I wonder perhaps the problem is with using = since that’s for number comparisons. Maybe try eq instead since that’s for string comparisons 

https://help.autodesk.com/view/ACDLT/2025/ENU/?guid=GUID-F94A885A-4DA2-432B-AC1A-EB49CC6C1C72

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 12 of 13

PauloMiranda8553
Participant
Participant

That's the problem...
You made it.
Thank you very much... Appreciate that.

0 Likes
Message 13 of 13

paullimapa
Mentor
Mentor

It was a group effort…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos