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

help using if expression for labels

3 REPLIES 3
Reply
Message 1 of 4
andrewpuller3811
1783 Views, 3 Replies

help using if expression for labels

I am trying to use an if expression in the style editor to label a feature with no success as yet.

Expression reads

if ( length ( name ) > 5, substr (name, ( instr ( name, '/' ) +1 ) , ( length ( name ) - instr ( name, "/" ) - 1 ) ) , name)

I keep getting type mismatch error.

Where name is a string and / is a character to search for in the string

Basically, I want to check if the label is longer than 5 characters. Using - if ( length ( name ) > 5,

and return the end of the name string that is after the character "/" Using - substr (name, ( instr ( name, '/' ) +1 ) , ( length ( name ) - instr ( name, "/" ) - 1 ) )

otherwise return the name.

Anyone have any ideas?

The if statement comes in as -- If ( [condition], [trueValue], [falseValue] )

So i think I am doing it correctly.

I have tried using just basic elements and still et the same results. I have searched the help and it doesn't mention the IF expression, as well as checking with google, this newsgroup and various blogs.

Using Civil 3d 2010 Map features using FDO to connect to data files.


If a post provides a fix for your issue, click on "Accept as Solution" to help other users find solutions to problems they might have that are similar to yours.

Andrew Puller
Maitland, NSW, Australia
Windows 10 Enterprise 64bit
Intel core i7 11800 @ 2.30 GHz with 32GB Ram
Civil 3d 2021
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: andrewpuller3811

FWIW I racked my brain around the IF a few times and gave up on it. What I
did was created as couple calculation fields converting to strings and back
and using substr or something then used one of those to label with.

--

Murph
http://map3d.wordpress.com/


"andrewpuller3811" wrote in message news:6340010@discussion.autodesk.com...
I am trying to use an if expression in the style editor to label a feature
with no success as yet.

Expression reads

if ( length ( name ) > 5, substr (name, ( instr ( name, '/' ) +1 ) , (
length ( name ) - instr ( name, "/" ) - 1 ) ) , name)

I keep getting type mismatch error.

Where name is a string and / is a character to search for in the string

Basically, I want to check if the label is longer than 5 characters. Using -
if ( length ( name ) > 5,

and return the end of the name string that is after the character "/"
Using - substr (name, ( instr ( name, '/' ) +1 ) , ( length ( name ) - instr
( name, "/" ) - 1 ) )

otherwise return the name.

Anyone have any ideas?

The if statement comes in as -- If ( [condition], [trueValue],
[falseValue] )

So i think I am doing it correctly.

I have tried using just basic elements and still et the same results. I have
searched the help and it doesn't mention the IF expression, as well as
checking with google, this newsgroup and various blogs.

Using Civil 3d 2010 Map features using FDO to connect to data files.
Message 3 of 4

Thanks Murph.


If a post provides a fix for your issue, click on "Accept as Solution" to help other users find solutions to problems they might have that are similar to yours.

Andrew Puller
Maitland, NSW, Australia
Windows 10 Enterprise 64bit
Intel core i7 11800 @ 2.30 GHz with 32GB Ram
Civil 3d 2021
Message 4 of 4

Just an update on using the if statement in expressions for labels.

With help from autodesk support, I got the statement working.

The main problem with the if statement was that it expects strings in all 3 parts of the statement, here the statement I was using was not returning a string for the first part. To get it to work, the first part only needed to be put in single appostraphies, which apparently creates a string out of the evaluated expression inside, allowing the IF statement to work.

So the final working statement is below.

if ( 'length ( name ) > 5', substr (name, ( instr ( name, '/' ) +1 ) , length ( name ) - instr ( name, '/' ) ) , name)


If a post provides a fix for your issue, click on "Accept as Solution" to help other users find solutions to problems they might have that are similar to yours.

Andrew Puller
Maitland, NSW, Australia
Windows 10 Enterprise 64bit
Intel core i7 11800 @ 2.30 GHz with 32GB Ram
Civil 3d 2021

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

Post to forums  

Autodesk Design & Make Report

”Boost