Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DIESEL parsing

14 REPLIES 14
Reply
Message 1 of 15
sbrusco
2480 Views, 14 Replies

DIESEL parsing

Hi All,

Is there a simple diesel expression to find the part of a string that is between the first space " " and the first "-"?

Our drawings are named using the job number, a space " ", the drawing number, a dash "-" then the issue. For example, 12345 E01-2.

I want to set the value of an attribute in a block equal to the drawing name, which falls between the first blank and the first dash. The only way i know to do this is with diesel but i can't figure out the syntax.

Please help.

Thanks,
Sal

14 REPLIES 14
Message 2 of 15
Anonymous
in reply to: sbrusco

Something like:

$(substr,$(getvar, "dwgname"),6,$(-,$(strlen,$(getvar, "dwgname")),4))

maybe?

As long as the job number is always 5 characters long...




wrote in message news:4937113@discussion.autodesk.com...
Hi All,

Is there a simple diesel expression to find the part of a string that is
between the first space " " and the first "-"?

Our drawings are named using the job number, a space " ", the drawing
number, a dash "-" then the issue. For example, 12345 E01-2.

I want to set the value of an attribute in a block equal to the drawing
name, which falls between the first blank and the first dash. The only way i
know to do this is with diesel but i can't figure out the syntax.

Please help.

Thanks,
Sal
Message 3 of 15
Anonymous
in reply to: sbrusco

You may want to use RTEXT in your block instead of an attribute. Then it
always reads the correct dwg name.

$(substr,$(getvar, "dwgname"),6,$(-,$(strlen,$(getvar, "dwgname")),6))
Message 4 of 15
sbrusco
in reply to: sbrusco

Hi Allen,

and thanks for your response. Unfortunately the job number is either 5 or 6 chars long and the dwg number should not include the chars after the '-'. Because of this, i think some sort of char recognition has to be built into the expression.

Any other ideas or suggestions would be appreciated.
Sal

Message 5 of 15
sbrusco
in reply to: sbrusco

Hi,

Thats an interesting option but what i'm doing is making the attribute hidden and constant so that i can *extract* the information about the drawing *with* the block. Because of our naming convention all the info i need is in the dwg name, i just need to parse it for the block. Correct me if i'm wrong but i don't think i can extract rtext from the block.

Thanks again,
Sal

Message 6 of 15
Anonymous
in reply to: sbrusco

Actually this string works for the drawing name you indicated to return
"E01"

$(substr,$(getvar, "dwgname"),6,$(-,$(strlen,$(getvar, "dwgname")),11))
Message 7 of 15
Anonymous
in reply to: sbrusco

You could use the $if function to check the length of the string, then
return either 5 or 6, depending on if the length of the string is 15 or 16
characters long....

$(substr,$(getvar, "dwgname"),$(if,$(=,$(strlen,$(getvar,
"dwgname")),15),5,6)(,$(-,$(strlen,$(getvar, "dwgname")),11))

or

$(substr,$(getvar, "dwgname"),$(-,$(strlen,$(getvar,
"dwgname")),15)(,$(-,$(strlen,$(getvar, "dwgname")),11))
Message 8 of 15
sbrusco
in reply to: sbrusco

Unfortunately, with 30 users, our naming convention is really just a 'guideline' in some minds. That same dwg could be named:
12345 E1.dwg
12345 E1-0.dwg or
12345 E1 0.dwg
and some other names for different types of dwg prefixes would be:
12345 GN1.dwg
12345 GN01.dwg
12345 GN1-0.dwg
12345 D1.dwg
12345 D1-0.dwg
12345 D01-0.dwg
12345 KP1.dwg.......
So you see, the len of the dwg name can vary and the job number can be either 5 or 6 chars long.

I think i like your first suggestion for determining the dwg number by removing the last 4 chars. Its really no consequence if the extraction returns D01, D1, D1-0, D01-0...

The only question still open is how to determine where that first space (" ") is because the job num can be either 5 or 6 chars. For now, 5 chars should work but we will soon be into 6 chars and i'll need to rewrite the expression. If i could build it into the expression now, it would save time later.

Unless i get an alternative to your very first suggestion (thanks again) i'll just go with that and cross the 6 char bridge when i come to it.

Thanks for all the ideas,
Sal

Message 9 of 15
Anonymous
in reply to: sbrusco

Maybe do a two step process (parse the string twice). Modify the codes below
to meet your needs.
Code from Jeff Mishler and help from Juerg Menzi.

;;;strip string from right
;;;Jeff Mishler
(defun ARCH:StripRight (str delim /)
(if (setq pos (vl-string-position (ascii delim) str))
(substr str 1 (1+ pos))
nil))
;;;strip string from left
(defun ARCH:StripLeft (str delim / )
(if (setq pos (vl-string-position (ascii delim) str))
(substr str (1+ pos))
nil
)
)
;|
_$ (ARCH:StripLeft "A-XYZ-B" "-")
"-XYZ-B"
_$ (ARCH:StripRight "A-XYZ-B" "-")
"A-"
|;
(defun ARCH:Strip-Left (str del / pos)
(if (setq pos (vl-string-position (ascii del) str nil T))
(substr str (+ pos 2))
nil
)
)
(defun ARCH:Strip-Right (str del / pos)
(if (setq pos (vl-string-position (ascii del) str nil nil))
(substr str 1 pos)
nil
)
)
;|
_$ (ARCH:Strip-Left "A-XYZ-B" "-")
"B"
_$ (ARCH:Strip-Right "A-XYZ-B" "-")
"A"
|;



(ARCH:StripRight "12345 GN1-0.dwg" "-")
"12345 GN1-"

(ARCH:StripLeft "12345 GN1-" " ")
" GN1-"






--
For a moment, nothing happened...

Thanks
Gary Fowler








Then, after a second or so, nothing continued to happen.


wrote in message news:4937113@discussion.autodesk.com...
Hi All,

Is there a simple diesel expression to find the part of a string that is
between the first space " " and the first "-"?

Our drawings are named using the job number, a space " ", the drawing
number, a dash "-" then the issue. For example, 12345 E01-2.

I want to set the value of an attribute in a block equal to the drawing
name, which falls between the first blank and the first dash. The only way i
know to do this is with diesel but i can't figure out the syntax.

Please help.

Thanks,
Sal
Message 10 of 15
sbrusco
in reply to: sbrusco

Hi Gary,

This is good code for my archives, but i need it in diesel because i want to put it in an attribute and i don't know how to put VL in as a value.

Can this be written as diesel?

If not, any suggestions in diesel?

Thanks,
Sal

Message 11 of 15
Anonymous
in reply to: sbrusco

You could check to see if the sixth character is a space or number and vary
the starting position accordingly...

$(if,$(=,$(substr,$(getvar,"dwgname",6,1))," "),5,6)
Message 12 of 15
sbrusco
in reply to: sbrusco

I haven't tried this yet but from what i'm learning about diesel, this looks good to me.

I did try your first suggestion and it works just like you said it would. Now i have another question. When i 'save as' another name (but the same convention we've discussed) and re-extract the attributes, the drawing name doesn't reflect the new number. Is there some way to 'update' (?) the attribute without re-inserting it?

I saved the drawing named 12345 E1-1 as 12345 E01-1 and when i opened the new drawing i expected the attributes to be different and they weren't.

Thanks for all your help.
Sal

Message 13 of 15
sbrusco
in reply to: sbrusco

never miiind. After a little, and i do mean little, i found UPDATEFIELD. I just have to remember to run that before the extractions.

Message 14 of 15
sbrusco
in reply to: sbrusco

Thanks to Allen for all his help in refining this solution. This is what i've ended up with and if there is a better way, *please* share it with me as i'm still learning diesel and would appreciate any constructive criticism.

For the job number, which is the first 5 or 6 characters before the first space, i use:

$(SUBSTR,$(GETVAR,"DWGNAME"),1,$(if,$(eq,$(substr,$(getvar,"dwgname"),6,1)," "),5,6))

For the drawing number, which is everything after that first space and before the '.dwg' extension, i use:

$(substr,$(getvar,"dwgname"),$(if,$(eq,$(substr,$(getvar,"dwgname"),6,1)," "),7,8),$(-,$(strlen,$(getvar,"dwgname")),$(if,$(eq,$(substr,$(getvar,"dwgname"),6,1)," "),10,11)))

WOW, did that come out of me? While it may not be very elegant, it works. But if there is a better way, please share.

Thanks again Allen,

Sal

Message 15 of 15
Anonymous
in reply to: sbrusco

Buenos dias,

 

Estoy buscando lo mismo que buscabas tu, eliminar "x" caracteres del nombre del archivo tanto por delante como por detras independientemente de la longitud de caracteres que tenga el nombre del archivo, he probado tu cadena, pero... no me la reconoce, me podrias ayudar?

 

$(substr,$(getvar,"dwgname"),$(if,$(eq,$(substr,$(getvar,"dwgname"),6,1)," _7,8)$(-,$(strlen,$(getvar,"dwgname")),$(if,$(eq,$(substr,$(getvar,"dwgname"),6,1)," [10,11)))

 

 

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

Post to forums  

Forma Design Contest


AutoCAD Beta