How to extract parts of the route on lisp ?

How to extract parts of the route on lisp ?

Anonymous
Not applicable
1,306 Views
6 Replies
Message 1 of 7

How to extract parts of the route on lisp ?

Anonymous
Not applicable

Hi people, this my first post here i have read you months ago, now i wanna to clear some things.

What i want to do is the following:

Using lisp i wanna extract parts of the route, by example:

The route of draw is "C:\XXX\Works\DUSTIN\JUNE\example.dwg"

 

I want to separate the route into 5 variables:

var1 = XXX

var2 = Works

var3 = DUSTIN

var4 = JUNE

var5 = example.dwg

 

Another thing that I would like to find out is to know if I have these variables I can complete attributes of a block in an automated or semi automated way. Example:

 

ATTRIBUTES (All are in 1 block):

ROUTE1: fill this attribute with "var1"

ROUTE2: fill this attribute with "var2"

LKD: fill this attribute with "var3"

DATE02: fill this attribute with "var4"

DRAW: fill this attribute with "var5"

 

Thats all for me, i want to thank you in advance..

PD: Sorry for my english, is not good, but in spanish forum i havent a clear answer.

 

0 Likes
Accepted solutions (1)
1,307 Views
6 Replies
Replies (6)
Message 2 of 7

ronjonp
Mentor
Mentor

How familiar are you with lisp?

 

Here is a start to your question:

(defun _parse (str del / i)
  (if (setq i (vl-string-search del str))
    (vl-remove "" (cons (substr str 1 i) (_parse (substr str (+ i 1 (strlen del))) del)))
    (list str)
  )
)
;; Parse path and remove drive
(setq l (cdr (_parse (strcat (getvar 'dwgprefix) (getvar 'dwgname)) "\\")))
;; Bind parts of list to variables
(mapcar 'set '(var1 var2 var3 var4 var5) l)
Message 3 of 7

Anonymous
Not applicable

Hi, Ron, thanks for the prompt response.

I need to told you this is my first lisp code, i only do some small things in the command line of AutoCAD.

 

I going to test what you just passed and analyze in cold because i do not understand it at all, I need to look for each command (i call command to "str", "substr", "defun") to know what it does and how it works as well as the structure. Again, I thank you.

 

PD: Do you have a link to the explain to all "commands" ? (i know they arent commands, whats the correct word ?)

0 Likes
Message 4 of 7

ronjonp
Mentor
Mentor

@Anonymous wrote:

PD: Do you have a link to the explain to all "commands" ? (i know they arent commands, whats the correct word ?)


HERE is a good start to learn the functions. 🙂

 

If you post a sample drawing with your block I can help you more.

Message 5 of 7

Anonymous
Not applicable

Ron, here is the block i'll fill with the bars... following the example:

The route of draw is "C:\XXX\Works\DUSTIN\JUNE\example.dwg"

ATTRIBUTES OF THE BLOCK:

 

RUTA-1: fill this attribute with "var1"

RUTA-2: fill this attribute with "var2"

LKD: fill this attribute with "var3"

DATE02: fill this attribute with "var4"

PLANO-N: fill this attribute with "var5"

 

The others do not need to be completed automatically or complete them with DIESEL fields.

 

0 Likes
Message 6 of 7

ronjonp
Mentor
Mentor

I ran out of time today but I'll get something together in the next few days.

Message 7 of 7

Anonymous
Not applicable
Accepted solution

Dear Ron.

I'm happy to tell you I could do what I was looking for.

I answer if you were still working on it; and to clarify what I did in case some other user was looking for something similar.

the code he used was:

 

(defun c:FHEREDIA() ;just example haha
;;;;; COMIENZO DE LA RUTINA ;;;;;
; - LLAMADO DE LA RUTA - ;
(setq _ruta (substr (getvar 'dwgprefix) 37)
;I DESIRE THE FIRST 36 CHARACTERS, BECAUSE THEY ARE PART OF
;MY SERVERS ROUTE AND ARE THE SAME FOR ALL MY FILES
;\\SERVER\tecnica\AUTOCAD_1\
;AND THE CHARACTER NUMBER 37 BECAUSE I DELETE THE FIRST SLASH
)
(setq nruta1
;COUNT THE CHARACTERS UNTIL THE NEXT SLASH
(vl-string-search "\\" _ruta 2)
)
(setq ruta1 
(substr _ruta (+ nruta1 1))
;CUTTING THE ROUTE WITHOUT THE FIRST ITEM I ALREDY
;KNOW HOW TO CUT IN "Cliente"
)
(setq nruta2 ;repeat
(vl-string-search "\\" ruta1 2)
)
(setq ruta2 ;repeat
(substr ruta1 (+ nruta2 1))
)
(setq cliente ;set and cutting at 16characters
(if
(<= (strlen (substr _ruta 1 nruta1)) 16)
(substr _ruta 1 nruta1)
(strcat (substr _ruta 1 16) "...")
)
)
(setq presupuesto (substr ruta1 2 (- nruta2 1))) ; set
(setq estado (vl-string-trim "\\" ruta2)) ; set
;;;;; FIN DE LA RUTINA ;;;;;
)

Thats all.. i calling the variables with DIESEL

%<\AcVar.17.0 Lisp.cliente>%
%<\AcVar.17.0 Lisp.presupuesto>%
%<\AcVar.17.0 Lisp.estado>%

I'm doubting if that .17 takes into account that my autocad is 2017 and will not work correctly in other versions.

And that would be all I did so far, although it is a pretty beginner code, it helped me a lot.

 

I wanted to thank you for the link you sent me about the functions, it was very helpful.

Greetings.

 

 

 

 

0 Likes