Change DXF code

Change DXF code

andreas7ZYXQ
Advocate Advocate
2,433 Views
13 Replies
Message 1 of 14

Change DXF code

andreas7ZYXQ
Advocate
Advocate

Hi.

Im looking for a simple code that will change my dxf code.

In the list below i have my code. I would like to change that to a specific value. For example (90 . 643 ) to (90 . 5). So its important that it wont change the other codes in the list thats also 90.

 

(90 . 643)

 

Ive got 3 different codes that i want to choose between (ex. 643 / 644 / 645). Im thinking about a solution that uses kword so i can choose by clicking on it in the command line and activates the command so i can loop and choose until cancel.

 

Does anyone have a monite over and could assist me witht his or have something that could be edited to fulfil my needs?

 

My idea is something like this:
Start command
Select kword
Select object to change
(start and activate command again.)


If someting is unclear just ask, sorry for my english and beginner level. 😕

 

(-1 . <Entity name: 22f2b0ded50>)
(0 . MAGIELECTRICALCABLE)
(330 . <Entity name: 2271eed6e50>)
(5 . 14C5)
(100 . AcDbEntity)
(67 . 0)
(410 . Model)
(8 . E-63B--CE-)
(62 . 7)
(100 . MAGIELECTRICALENTITY)
(70 . 801)
(71 . 0)
(72 . 3)
(40 . 1.0)
(41 . 1.0)
(73 . 0)
(74 . 0)
(75 . 0)
(76 . 0)
(70 . 2)
(70 . 2001)
(70 . 7)
(70 . 2002)
(70 . -3)
(70 . 8)
(70 . 2001)
(70 . 1001)
(70 . 1011)
(280 . 0)
(70 . 6046)
(300 . 0c9OZ558H2$xtiIzgTNyHI)
(70 . 2015)
(70 . 1)
(70 . 3001)
(90 . 1)
(70 . 3002)
(90 . 1)
(70 . 3004)
(90 . 643)
(70 . 2010)
(70 . 3)
(100 . MAGIELECTRICALPOLYLINE)
(70 . 0)
(40 . 10.0)
(41 . 0.0)
(42 . 0.0)
(43 . 0.0)
(44 . 0.0)
(45 . 0.0)
(46 . 0.0)
(71 . 2)
(10 58403.9 120882.0 0.0)
(10 58399.5 121835.0 0.0)
(72 . 0)
(74 . 0)

/ante

0 Likes
Accepted solutions (1)
2,434 Views
13 Replies
Replies (13)
Message 2 of 14

DannyNL
Advisor
Advisor

Something like this?

 

(defun c:Test (/ T_Option T_Selection T_Entity)
   (initget "643 644 645")
   (if
      (and
         (setq T_Option (getkword "\Select code to change [643/644/645]: "))
         (setq T_Selection (ssget))
      )
      (foreach T_Object (vl-remove-if '(lambda (T_Item) (listp (cadr T_Item))) (ssnamex T_Selection))         
         (entmod (mapcar '(lambda (T_Pair) (if (and (= (car T_Pair) 90)(= (cdr T_Pair) (atoi T_Option))) '(90 . 5)  T_Pair)) (entget (setq T_Entity (cadr T_Object)))))
         (entupd T_Entity)
      )
   )
   (princ)
)
0 Likes
Message 3 of 14

andreas7ZYXQ
Advocate
Advocate

Thanks for the help, but it wont work for me.

 

and the code is a bit advanced (mapcar lambda)for med to read it. I forgot to say that the dxf code 

(90 . 643)

could be  anything ex ( 90 . X ), so i want to override my X with the kword number.

0 Likes
Message 4 of 14

Kent1Cooper
Consultant
Consultant

@andreas7ZYXQ wrote:

.... I would like to change that to a specific value. For example (90 . 643 ) to (90 . 5). So its important that it wont change the other codes in the list thats also 90. ….

Ive got 3 different codes that i want to choose between (ex. 643 / 644 / 645). ….


 

I don't think it's necessary to "open up" the (90 . xxx) entries in entity data and check the (car) and (cdr) values separately.  You can replace the complete dotted pair, without worrying about any other (90 . xxx) pairs, as long as there won't be more than one with that same 643 / 644 / 645 value in it.

 

After selecting between 643 / 644 / 645 [setting the choice into a variable, let's say 'old90'], and selecting the object [putting its entity data list into a variable, let's say 'edata'], this should replace it:

 

(entmod (subst '(90 . 5) (cons 90 (atoi old90)) edata))

Kent Cooper, AIA
0 Likes
Message 5 of 14

Kent1Cooper
Consultant
Consultant

@andreas7ZYXQ wrote:

... the dxf code (90 . 643) could be  anything ex ( 90 . X ), so i want to override my X with the kword number.


 

Now you're describing what looks like the opposite of the original statement.  The original said you wanted to change from  (90 . 643) to (90 . 5), but this now looks like you want to change to  (90 . 643).  Which way are you going?

Kent Cooper, AIA
0 Likes
Message 6 of 14

DannyNL
Advisor
Advisor

 

If you want to learn LISP, why don't you take my code an dissect it and use the help to figure out what the code is doing. It looks complicated but if you break it down piece by piece, it shouldn't be too difficult to see what is happening. 

 

But now I'm confused as well. According to the first post the code was meant to change a specific value to (90 . 5).

 

I did take into account that there might be multiple (90 . x) codes that needed to be changed (since the example also has multiple (90. x) codes), hence why I process each item in the list (that's what the mapcar is for). 

 

But what do you exactly want to do and in what order, so I can modify the code for you. What values are variable and need your input and what values can be hard coded in the routine?

0 Likes
Message 7 of 14

andreas7ZYXQ
Advocate
Advocate

im sorry i messed upp my description.

I want to look for (90.xxx) and change to (90 . 643).


(In the position where it says (90 . 643) in the dxf list i posted , its the code/position i want to change. But it will not always say 90 . 643. The number 643 varies. I would like to change this matching the kword. )

0 Likes
Message 8 of 14

ronjonp
Mentor
Mentor

@andreas7ZYXQ wrote:

im sorry i messed upp my description.

I want to look for (90.xxx) and change to (90 . 643).


(In the position where it says (90 . 643) in the dxf list i posted , its the code/position i want to change. But it will not always say 90 . 643. The number 643 varies. I would like to change this matching the kword. )


Assuming your 90's have different vales this should work:

(defun c:foo (/ e)
  (if (setq e (car (entsel "\nPick something: ")))
    (entmod (mapcar '(lambda (x)
		       (cond ((= 90 (car x)) '(90 . 643))
			     (x)
		       )
		     )
		    (entget e)
	    )
    )
  )
  (princ)
)
0 Likes
Message 9 of 14

Kent1Cooper
Consultant
Consultant

@andreas7ZYXQ wrote:

....
I want to look for (90.xxx) and change to (90 . 643).

....


 

Does that mean you need two  User inputs, one for the xxx and  one for the 643 [or other (getkword) return]?  They could both be by (initget)/(getkword) if they're both always among limited possible values, or one or both could be wide open for the User to enter any value.

Kent Cooper, AIA
0 Likes
Message 10 of 14

andreas7ZYXQ
Advocate
Advocate

This is almost what im looking for. If seen on the list below this one will change all 90 dxf codes. There is a problem with that, i only want to change the last one. in the liste because thats where my information is stored.

therefor it have to skip the first 2 "90" codes

 

(-1 . <Entity name: 1f776aad840>)
(0 . MAGIELECTRICALCABLE)
(330 . <Entity name: 1f75456e650>)
(5 . 12A4)
(100 . AcDbEntity)
(67 . 0)
(410 . Model)
(8 . E-63B--CE-)
(62 . 7)
(100 . MAGIELECTRICALENTITY)
(70 . 801)
(71 . 0)
(72 . 3)
(40 . 1.0)
(41 . 1.0)
(73 . 0)
(74 . 0)
(75 . 1)
(330 . <Entity name: 1f776aad850>)
(76 . 0)
(70 . 2)
(70 . 2001)
(70 . 7)
(70 . 2002)
(70 . -3)
(70 . 8)
(70 . 2001)
(70 . 1001)
(70 . 1011)
(280 . 0)
(70 . 6046)
(300 . 1rxlRJqET6Qv1r9yW$oYS0)
(70 . 2015)
(70 . 1)
(70 . 3001)
(90 . 643) <<<------- Not this one
(70 . 3002)
(90 . 643) <<<------- Not this one
(70 . 3004)
(90 . 643) <<<------- this is the only code that i want to change.
(70 . 2010)
(70 . 3)
(100 . MAGIELECTRICALPOLYLINE)
(70 . 0)
(40 . 10.0)
(41 . 0.0)
(42 . 0.0)
(43 . 0.0)
(44 . 0.0)
(45 . 0.0)
(46 . 0.0)
(71 . 2)
(10 75235.9 144483.0 0.0)
(10 77316.0 146980.0 0.0)
(72 . 0)
(74 . 0)
0 Likes
Message 11 of 14

andreas7ZYXQ
Advocate
Advocate

First input is that i want to select my object

The second one is my kword option in command line.

See my post above, it works alomst as i want (without the kword option though).

0 Likes
Message 12 of 14

DannyNL
Advisor
Advisor
Accepted solution

OK, try this one.

First select your object, second select a predefined new value or type in a new value (>0).

 

(defun c:Test (/ T_Entity T_Elist T_NewValue T_Found T_Count)
   (if
      (and
         (setq T_Entity (car (entsel)))
         (assoc 90 (setq T_Elist (reverse (entget T_Entity))))
      )
      (progn
         (initget 6 "643 644 645")
         (if
            (setq T_NewValue (getint "\nSelect new value [643/644/645]: "))
            (progn
               (setq T_Found (vl-position (assoc 90 T_Elist) T_Elist))
               (setq T_Count -1)
               (entmod (reverse (mapcar '(lambda (T_Item) (if (= (setq T_Count (1+ T_Count)) T_Found) (cons 90 T_NewValue) T_Item)) T_Elist)))
               (entupd T_Entity)
               (princ (strcat "\n ** Changed  value to " (itoa T_NewValue)))
            )
 (princ "\n ** No new value entered!") ) ) (princ "\n ** Nothing selected or DXF code 90 not found in object data!") ) (princ) )
0 Likes
Message 13 of 14

andreas7ZYXQ
Advocate
Advocate

Works perfect!  thansk alot.

i will try to break it down and learn this routine. 


Thanks again everyone.

0 Likes
Message 14 of 14

DannyNL
Advisor
Advisor

You're welcome & glad I could help Smiley Happy

 

BTW, code below slightly modified to remove some duplicate code.

 

(defun c:Test (/ T_Entity T_Check T_Elist T_NewValue T_Found T_Count)
   (if
      (and
         (setq T_Entity (car (entsel)))
         (setq T_Check (assoc 90 (setq T_Elist (reverse (entget T_Entity))))))
      )
      (progn
         (initget 6 "643 644 645")
         (if
            (setq T_NewValue (getint "\nSelect new value [643/644/645]: "))
            (progn
               (setq T_Found (vl-position T_Check T_Elist))
               (setq T_Count -1)
               (entmod (reverse (mapcar '(lambda (T_Item) (if (= (setq T_Count (1+ T_Count)) T_Found) (cons 90 T_NewValue) T_Item)) T_Elist)))
               (entupd T_Entity)
               (princ (strcat "\n ** Changed  value to " (itoa T_NewValue)))
            )
            (princ "\n ** No new value entered!")
         )
      )
      (princ "\n ** Nothing selected or DXF code 90 not found in object data!")
   )
   (princ)
)
0 Likes