Jump to content

Recommended Posts

Posted

In my drawings I use a diesel expression to extract from the filename, only the final part that contains the client code.
Now I made a better version of it, but I don't know how to replace it quickly in my drawings, using a lisp.

 

I use:

$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),9),6)

 

"Name of customer_24-999.dwg"    ->    24-999   <--- OK

 

"Name of customer_24-1000.dwg"    ->    4-1000   <---- Error  

 

I solved it with:

 

$(if,$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),7),1)"1",$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),10),7),$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),9),6))

 

"Name of customer_24-999.dwg"    ->    24-999  <--- OK

 

"Name of customer_24-1000.dwg"    ->    24-1000  <--- OK

 

If I try to extract DXF data I only get the text string (24-999) not the Diesel expression that creates it!

Prova. 24-999.dwg Prova. 24-1000.dwg

Posted

Did you extract the data OK with the old expression?

 

 

(I don't use Diesel functions or really do much with DXF but DXF is stripped back drawing file able to be read by most packages, as such it might strip out the Diesel expression as a part of that process)

Posted

Just a cooment if your file name has "_" all the time can look for that using lisp then extract the string starting at the "_" .

 

(setq dwgname (getvar 'dwgname))
(setq pos (+ 2 (vl-string-position 95 Dwgname))) ; chr 95 is underscore
(setq ans (substr dwgname pos (- (strlen dwgname) pos 3)))

 

 

Posted
14 hours ago, BIGAL said:

Just a cooment if your file name has "_" all the time can look for that using lisp then extract the string starting at the "_" .

 

(setq dwgname (getvar 'dwgname))
(setq pos (+ 2 (vl-string-position 95 Dwgname))) ; chr 95 is underscore
(setq ans (substr dwgname pos (- (strlen dwgname) pos 3)))

 

 

@BIGAL You can't use regular AutoLISP expression in a FIELD. I think the OP wants something that will automatically populate based on the name of the drawing file, say in the title block. That being said:

 

@X11start Does this value become static once the drawing is named? If so, you could use a start-up AutoLISP routine to look for the text or attribute you want to populate, then fill in the correct value. You don't necessarily need a FIELD. The start-up routine could also re-fill the string if the drawing name is changed at the next time it is opened, or in real-time with a reactor. 

Posted

I tend to shy away from automatic changes, partly different clients have different naming conventions for files and drawings to make that trickier. However, if all drawings follow the same conventions then yes, a short LISP to check things out as things open is a handy tool.

  • Like 1
  • Agree 1
Posted
On 12/5/2024 at 11:19 PM, Steven P said:

Did you extract the data OK with the old expression?

 

 

(I don't use Diesel functions or really do much with DXF but DXF is stripped back drawing file able to be read by most packages, as such it might strip out the Diesel expression as a part of that process)

I used the word "DXF" incorrectly... Actually I just wanted to say that if I do (Entsel) on the text that contains a data field, I find "24-999", I don't find the diesel string of the field $(substr,$(getvar,dwgname),$(-,$....

 

Posted
On 12/6/2024 at 3:20 PM, pkenewell said:

@BIGAL You can't use regular AutoLISP expression in a FIELD. I think the OP wants something that will automatically populate based on the name of the drawing file, say in the title block. That being said:

 

@X11start Does this value become static once the drawing is named? If so, you could use a start-up AutoLISP routine to look for the text or attribute you want to populate, then fill in the correct value. You don't necessarily need a FIELD. The start-up routine could also re-fill the string if the drawing name is changed at the next time it is opened, or in real-time with a reactor. 

@pkenewell you have centered my request: the data field remains fixed as soon as I assign the name to the file: try to rename one of the 2 DWGs I have attached. Interesting your idea of putting a lisp in the startup to make it edit the text!

 

Thank you all for the answers and for your availability!

Posted
Quote

If I try to extract DXF data I only get the text string (24-999) not the Diesel expression that creates it!

For obtain field code, you can use this:

(vla-fieldcode (vlax-ename->vla-object (car (entsel))))

For put field code in existing text, for exemple you can do this:

(vlax-put
  (vlax-ename->vla-object (car (entsel)))
  'TextString
  (strcat
    "%<\\AcDiesel"
    "$(edtime,$(getvar,tdcreate),DD\"/\"M\"/\"YYYY)"
    ">%"
  )
)

 

Posted (edited)

You can certainly find the block with an attribute and update it, you can find all instances etc, even those in layouts using a lisp starting with above code. Oh yeah you changed the rules used "_" originally now used "-"

 

(defun c:wow ( / dwgname pos ans x att obj)
(setq dwgname (getvar 'dwgname))

(if (wcmatch  dwgname "*_*")
  (setq pos (+ 2 (vl-string-position 95 Dwgname))) ; chr 95 is underscore
  (setq pos (+ 2 (vl-string-position 45 Dwgname))) ; chr 45 is minus
)
(setq ans (substr dwgname pos (- (strlen dwgname) pos 3)))

(setq ss (ssget "X" '((2 . "DATI TEST"))))

(if (= ss nil)
  (progn (alert "No DATI TEST found will exit now")(exit))
)

(repeat (setq x (sslength ss))
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
  (setq att (nth 0 (vlax-invoke obj 'Getattributes)))
  (vlax-put att 'textstring ans)
)

(princ)
)
(c:wow)

image.png.6b1f0e7b5780c2381d8c13c9b4d97378.png

Edited by BIGAL
Posted
16 hours ago, Tsuky said:
(vlax-put
  (vlax-ename->vla-object (car (entsel)))
  'Stringa di testo
  (strcat
    "%<\\AcDiesel"
    "$(edtime,$(getvar,tdcreate),GG\"/\"M\"/\"AAAA)"
    ">%"
  )
) 

Thank you all for your interest: I solved with @Tsuky's suggestion. I created a small lisp file with a single command:

 

(vlax-put(vlax-ename->vla-object (car (entsel)))'TextString"%<\\AcDiesel $(if,$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),7),1)\"1\",$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),10),7),$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),9),6))>%")

 

If I open a drawing and see that the data field is wrong, I launch the lisp that copies the long diesel string, instead of the old one.

 

... much faster solution than going into each data field using DCL and copying the string!

Thank you very much!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...