Editing AutoCAD Field Expression or Diesel expression editing - Insert file name

Editing AutoCAD Field Expression or Diesel expression editing - Insert file name

Anonymous
Not applicable
10,369 Views
14 Replies
Message 1 of 15

Editing AutoCAD Field Expression or Diesel expression editing - Insert file name

Anonymous
Not applicable

How would you enter a file name but remove the last four characters?

 

For example, after typing field in AutoCAD, you can grab the field expression string: 

%<\AcVar Filename \f "%tc1%fn2">%

 

Which will add the file name. 

 

How can you do this but remove the last four characters:

WL-A-XYZ_R1A would become WL-A-XYZ

 

So I dont have the revision R1A displayed

0 Likes
Accepted solutions (1)
10,370 Views
14 Replies
Replies (14)
Message 2 of 15

rkmcswain
Mentor
Mentor
Accepted solution

You can use this DIESEL expression.

 

$(substr,$(getvar,dwgname),1,$(-,$(strlen,$(getvar,dwgname)) ,8))

Which means the field code string will be:

 

%<\AcDiesel $(substr,$(getvar,dwgname),1,$(-,$(strlen,$(getvar,dwgname)) ,8))>%
R.K. McSwain     | CADpanacea | on twitter
Message 3 of 15

Anonymous
Not applicable

You can try this:

$(substr,$(getvar,"dwgname"),1,8)

di.gif

 

Message 4 of 15

rkmcswain
Mentor
Mentor
@Anonymous  wrote:
You can try this:
$(substr,$(getvar,"dwgname"),1,8)

That only works if the portion of the file name you want to retain is eight characters long.

 

See above, where that DIESEL statement reads the entire file name, no matter what the length, and removes the last eight characters, which is the four character suffix and the four characters ".DWG"

R.K. McSwain     | CADpanacea | on twitter
Message 5 of 15

Anonymous
Not applicable

@rkmcswain  Exactly!!  My expression goes from character 1 to 8, since its name is 12 it will remove the last 4.

 

His expression got much better Heart

0 Likes
Message 6 of 15

rkmcswain
Mentor
Mentor
@Frjuniornogueira  wrote:

Exactly!!  My expression goes from character 1 to 8, since its name is 12 it will remove the last 4.

That makes little sense. Why hardcode something to only work in one particular case, when it can be written so that it works in multiple scenarios?

R.K. McSwain     | CADpanacea | on twitter
Message 7 of 15

Anonymous
Not applicable

True, but how do you add that extra feature in the code? 

0 Likes
Message 8 of 15

Anonymous
Not applicable

¿Cuál sería la cadena para eliminar los caracteres "x" delante y "x" detrás. ¿Sin tener en cuenta la longitud del nombre de archivo? Gracias

0 Likes
Message 9 of 15

neabailey
Enthusiast
Enthusiast

@rkmcswain This has been super helpful. Is there a way to remove the first 4 characters instead of the last 4? For example making file name WSS-titleblock-01.dwg look like titleblock-01.dwg.

~nic

0 Likes
Message 10 of 15

dvicarioXT
Contributor
Contributor

That should be easier, try this:

 

$(substr,$(getvar,dwgname),5)

 

Where 5 is the position of the first character you pick. You can also exclude a certain amount of characters from the start AND the end, but it's a bit more complex (I'm not an expert, maybe there's a better way to do that):

 

$(substr,$(getvar,dwgname),5,$(-,$(strlen,$(getvar,dwgname)),8))

 

You take away 4 from the beginning (so you start with the 5th character) and 4 (8-4=4) from the end.

 

I hope that helps

Message 11 of 15

cadffm
Consultant
Consultant

deleted  ~superfluous~

Sebastian

0 Likes
Message 12 of 15

ryan_gajelomo
Community Visitor
Community Visitor

@rkmcswain can you help me with this? i am trying to get only the "ceiling light feature detail" only. but the last 11 characters are not removed.

 

this is the filename:

 

MDGI_MDG_L1_A0_X1.1.406_CEILING LIGHT FEATURE DETAIL_250801.dwg

 

and i used this diesel expression:

 

$(substr,$(getvar,dwgname),25,$(-,$(strlen,$(getvar,dwgname)) ,11))

 

i am trying to get only the "ceiling light feature detail". but the last 11 characters are not removed.

did i failed at somepoint? any help is much appreciated. thank you!

 

0 Likes
Message 13 of 15

cadffm
Consultant
Consultant

Hi,

and the part starts always with character 25 and ends 11 befor end ??

 

Substr , "string" , start character nr, length

 

String: dwgname

Start: 25

Length: full length - 24 - 11

 

Your "length" part should be:

$(-,$(strlen,$(getvar,dwgname)),35)

 

 

 

Untested

Sebastian

Message 14 of 15

ryan_gajelomo
Community Visitor
Community Visitor

 

hi, thanks for your reply. to answer your question, yes, it always begins with 25th character.

 

after searching for some time, i somewhat found a solution to my query. i forgot to save the link where i found it, but i think it's from cadtutor. 

 

Here's what he/she did:

 

$(substr,$(substr,$(getvar,"dwgname"),1,$(-,$(strlen,$(getvar,"dwgname")),11)),25) 

 

wherein it gets the whole string length that begins with the 25th character and subtract 11 last characters.

 

 

from filename: MDGI_MDG_L1_A0_X1.1.406_CEILING LIGHT FEATURE DETAIL_250801.dwg

 

result: ryan_gajelomo_1-1754035314001.png

 

it also works for my other files as well:

 

from filename: MDGI_MDG_L1_A0_X1.1.101_PARTITION WALL FINISH PLAN_250731

 

result: ryan_gajelomo_2-1754035466069.png

 

as of the moment, that query of mine is kinda solved.

 

what i'm having right now is this: 

 

ryan_gajelomo_3-1754035573934.png

some of the filenames has (example: X1.1.301a). 

now, i'm wondering how am i going to add-in the "a" without ruining the result.

 

please help. many thanks!

 

 

 

 

 

0 Likes
Message 15 of 15

cadffm
Consultant
Consultant

 

Hi,

 

>"as of the moment, that query of mine is kinda solved."

Glad to help

My DIESEL line would be: $(substr,$(getvar,dwgname),25,$(-,$(strlen,$(getvar,dwgname)),35))

 

 

 

>>"what i'm having right now is this: "

So, A sample filename could be: MDGI_MDG_L1_A0_X1.1.406aCEILING LIGHT FEATURE DETAIL_250801.dwg

Thats unusual, but otherwise your "always from 25" statement is wrong.

 

Let's see:

substr of DWGNAME

start with char 16

length: IF char 24 is "_", then length is 8, else length is 9

 

Take a look to the DIESEL catalog and IF function [F1]

$(substr,$(getvar,dwgname),16,$(if,$(eq,_,$(substr,$(getvar,dwgname),24,1)),8,9))

 

 

Sebastian

0 Likes