Lisp to change DXF codes on the fly

Lisp to change DXF codes on the fly

matt_sibum
Participant Participant
2,869 Views
8 Replies
Message 1 of 9

Lisp to change DXF codes on the fly

matt_sibum
Participant
Participant

Hi, 

 

I am wondering if anyone has a lisp to quickly change a DXF code that has a real number, to a different number.

 

This would be command line:

 

"Select entities"

"Specify DXF code to modify"

"Specify new real number to add to selected DXF code"

"DXF code XX updated"

 

This would obviously only work if the DXF code has a real number value, but error checking isnt required, I just need this to quickly test what certain DXF codes do.

 

Thanks

 

Matt

 

 

 

0 Likes
Accepted solutions (1)
2,870 Views
8 Replies
Replies (8)
Message 2 of 9

dlanorh
Advisor
Advisor

DXF Online Reference

I am not one of the robots you're looking for

Message 3 of 9

Kent1Cooper
Consultant
Consultant

@matt_sibum wrote:

.... I just need this to quickly test what certain DXF codes do. ....


 

 If that's the only purpose, I agree with @dlanorh -- you can simply look them up to find out.

 

And I can imagine all kinds of situations in which you may not learn anything by such a quick test.  For just one example, if you change the DXF code value for the thickness of any kind of object that has it [code 39], or the elevation of a Polyline [code 38], if you're looking straight down on it from above, you won't see any difference, so what will you have learned?

 

But it's certainly possible, if you really need to do it.

Kent Cooper, AIA
0 Likes
Message 4 of 9

dlanorh
Advisor
Advisor
You also need to be aware that certain dxf codes mean different things depending on the type of entity.

codes 40-48 => Double-precision floating-point values (text height, scale factors, and so on)

codes 70-78 => Integer values, such as repeat counts, flag bits, or modes

I am not one of the robots you're looking for

0 Likes
Message 5 of 9

john.uhden
Mentor
Mentor
Accepted solution

Hints:

(setq e (car (entsel)))     ... gets an entity name

(setq ent (entget e)))      ... gets the list of dxf entity data

For example:

((-1 . ) (0 . "LINE") (330 . ) (5 . "510A") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "E-CONC")

(100 . "AcDbLine") (10 5003.04 4888.12 0.0) (11 4996.05 4885.23 0.0) (210 0.0 0.0 1.0))

 

As you can see from that typical example, there are no dxf entries with only one real number.

To get one piece of dxf data by its dxf code...

(and

  (setq dxf (getint "\nEnter DXF code to change: "))

  (or

    (setq old (cdr (assoc dxf ent)))

    (prompt (strcat "\nDXF code " (itoa dxf) " does not exist for this entity."))

  )

  (princ "\nCurrent value is ")(princ old)

  (setq new (getreal "\nEnter new value: "))  *

  (entmod (subst (cons dxf new)(assoc dxf ent) ent))

)

* In reality, you had better check to see what type the old value is ('STR 'INT 'REAL) unless

you know for sure.  Changing 3-dimensional point lists (like dxf 10) is just a little more complicated.

John F. Uhden

0 Likes
Message 6 of 9

scot-65
Advisor
Advisor
Be aware that there are DFX codes that do not show in
the entity listing that will observe "ByLayer" conditions.

If missing, APPEND.
If the DFX is there, ENTMOD.

Examples: Color (62) and Linetype (6).

Instead, suggest playing with
DUMPALLPROPERTIES, GETPROPERTYVALUE and SETPROPERTYVALUE...
[where object dumping, (RO) is read only and property cannot be edited]

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 7 of 9

ronjonp
Advisor
Advisor

Try this to decipher the data types. Entmod after is relatively easy if you know what you're doing 🙂

(defun c:dxflist (/ e)
  (cond	((setq e (car (entsel "\nPick something to see DXF data: ")))
	 (mapcar '(lambda (x) (print (list (car x) (cdr x) (type (cdr x))))) (entget e '("*")))
	 (textscr)
	)
  )
  (princ)
)
0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor

My $0.05 use this and have a look at what you get, using VLISP is possibly easier at times. Be aware you can get an item and then go deeper into it eg Block -> Attributes -> 1 attribute properties.

 

;;;===================================================================; 
;;; DumpIt                                                            ; 
;;;-------------------------------------------------------------------; 
;;; Dump all methods and properties for selected objects              ; 
;;;===================================================================; 
(defun C:DumpIt ( / ent) 
  (while (setq ent (entsel)) 
    (vlax-Dump-Object 
      (vlax-Ename->Vla-Object (car ent)) 
    ) 
  ) 
  (princ) 
)
0 Likes
Message 9 of 9

matt_sibum
Participant
Participant

Thanks everyone, some great info here. 

 

The idea to open this can of worms started when I was viewing dxf data for an MTEXT object, comparing data when text frame is on and when it is off. I found 4 new dxf codes and was wondering what they do, but nothing came up on a search. I then thought if there was a way to quickly modify the real numbers for those codes, i could maybe reverse engineer what they are for. This only worked for dxf code 45, which is for the border offset. Still a great thing to know, so not a waste of time IMO.

 

Thanks @john.uhden for your code. Really appreciated.

 

0 Likes