Author Topic: How can I change DXF value ?  (Read 3326 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
How can I change DXF value ?
« on: May 28, 2012, 08:49:54 AM »
Sorry for my odd question.
How can I change DXF value?
for example
In TEXT
Code: [Select]
(1 . "X")To be
Code: [Select]
(1 . "Y")

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: How can I change DXF value ?
« Reply #1 on: May 28, 2012, 08:58:28 AM »
Example:

Code - Auto/Visual Lisp: [Select]
  1. (setq entity   (car (entsel))
  2.       dxfdata  (entget entity)
  3.       old-dxf  (assoc 1 dxfdata)
  4.       new-dxf '(1 . "Y")
  5.       dxfdata  (subst new-dxf old-dxf dxfdata)
  6. )
  7. (entmod dxfdata)

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How can I change DXF value ?
« Reply #2 on: May 28, 2012, 10:38:31 AM »
Example:
...
Whats wrong with this?
Code: [Select]
(defun c:rt (/ sset inc ss dxfdata old-dxf new-dxf dxfdata)

  (while T
    (if (setq sset (ssget "_:L" '((0 . "TEXT,MTEXT"))))
      (progn
(setq inc 0)
(setq ss (ssname sset inc))
(setq dxfdata  (entget ss))
(setq old-dxf  (assoc 1 dxfdata))
(setq new-dxf (cons 1 (round (atoi (cadr old-dxf)) 5)))
(setq dxfdata  (subst new-dxf old-dxf dxfdata))
(entmod dxfdata)
)
      )
    (setq inc (1+ inc))
     (princ "\n Type  rt  to Invoke")
     (princ)
  )
  )
(defun round (number by) ; http://www.theswamp.org/index.php?topic=3076.0;all
  (if (zerop by)
    number
    (+ (* (fix (/ number (setq by (abs by)))) by)
       (if (< (* 0.5 by) (rem number by)) by 0       )    )  ))

This line
Code: [Select]
(setq new-dxf (cons 1 (round (atoi (cadr old-dxf)) 5)))Gives error
Code: [Select]
; error: bad argument type: consp "7"

pBe

  • Bull Frog
  • Posts: 402
Re: How can I change DXF value ?
« Reply #3 on: May 28, 2012, 10:53:36 AM »
(atoi (cdr old-dxf))

better

(distof (cdr old-dxf))

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How can I change DXF value ?
« Reply #4 on: May 28, 2012, 11:03:11 AM »
this code working but when select one text only
Code: [Select]
(defun c:rt (/ sset n inc ss dxfdata old-dxf new-dxf dxfdata)

  (while T
    (if (setq sset (ssget "_:L" '((0 . "TEXT,MTEXT"))))
      (progn

(repeat (setq n (sslength sset))
(setq inc 0)
(setq ss (ssname sset inc))
(setq dxfdata  (entget ss))
(setq old-dxf  (assoc 1 dxfdata))
(setq new-dxf (cons 1 (itoa (round (distof (cdr old-dxf)) 5))))
(setq dxfdata  (subst new-dxf old-dxf dxfdata))
(entmod dxfdata)
(setq inc (1+ inc))
))
      )
   
     (princ "\n Type  rt  to Invoke")
     (princ)
  )
  )

pBe

  • Bull Frog
  • Posts: 402
Re: How can I change DXF value ?
« Reply #5 on: May 28, 2012, 11:14:14 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:rt (/ sset inc ss dxfdata old-dxf new-dxf dxfdata)
  2.  
  3.     (if (setq sset (ssget "_:L" '((0 . "TEXT,MTEXT"))))
  4.      (repeat (setq inc (sslength sset))
  5.         (setq ss (ssname sset (setq inc (1- inc))))
  6.         (setq dxfdata  (entget ss))
  7.         (setq old-dxf  (assoc 1 dxfdata))
  8.         (if (numberp (setq val  (read (cdr old-dxf))))
  9.                 (entmod  (subst (cons 1 (itoa (round val 5))) old-dxf dxfdata))
  10.         )
  11.       )
  12.         )
  13.      
  14.      (princ)
  15.   )(princ "\n Type  rt  to Invoke")

Watch out for MTEXT with formatting

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How can I change DXF value ?
« Reply #6 on: May 28, 2012, 11:52:32 AM »
LEE, gile Thanks working perfect

pBe

Tested with MTEXT and working. shall the code make errors with MTEXT?

pBe

  • Bull Frog
  • Posts: 402
Re: How can I change DXF value ?
« Reply #7 on: May 28, 2012, 12:33:42 PM »
pBe

Tested with MTEXT and working. shall the code make errors with MTEXT?

Of course it would HasanCAD, I did not say it will NOT work with Mtext   :-)
But Mtext  that has character formatting applied to any portion of the text. It will not error though , it just wont do anything is all.

e.g. "\\pxqr;12" <--Orientation option right justified . fortunately in your case you dont have to deal with those.

Glad you had it working.

Cheers




HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How can I change DXF value ?
« Reply #8 on: May 29, 2012, 02:18:26 AM »
Thanks pBe for the modifying the lisp and for clarification. this will be in mind when dealing with MTEXT.

pBe

  • Bull Frog
  • Posts: 402
Re: How can I change DXF value ?
« Reply #9 on: May 29, 2012, 04:01:14 AM »
Good for you.  Glad i could help.  :-)