Author Topic: Match Properties from nested item.. is it possible?  (Read 3570 times)

0 Members and 1 Guest are viewing this topic.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Match Properties from nested item.. is it possible?
« on: March 02, 2017, 07:55:39 AM »
Hi folks.
In some cases we need to change properties of selected object same to properties of nested object.
For example to change linetype and color of selected line same to line from xref..

In this case I do it by follow way:

1. Ncopy line from xref to current drawing
2. matchprop "ncopied" line to line I need to change
3. erase "ncopied" line
Is it possible to "automate" this prosses via lisp?

I did some "dirty" approaches, but all of it not working at all

Can somebody help me to solve this problem?

Any help will be very appretiated

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Match Properties from nested item.. is it possible?
« Reply #1 on: March 02, 2017, 09:08:27 AM »
I would assume that you would have to make sure the nested property you want to copy is valid for a non-nested entity.  In your example, a linetype would need to be renamed to one from the current drawing.

Not at windows computer right now, so the example might not be totally correct.
Nested linetype: <xref name>|<linetype name>
So take the items after (not including) the '|' symbol, and use them as the new property.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Match Properties from nested item.. is it possible?
« Reply #2 on: March 02, 2017, 09:13:17 AM »
.. it's no so simple as it seems T.Willey
Can you show me how to do it via  some lisp expressions?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Match Properties from nested item.. is it possible?
« Reply #3 on: March 02, 2017, 09:18:05 AM »
Typed without any testing (and a long time since I typed Lisp code of the top of my head)

Code: [Select]
(setq sel (nentsel "\n Select item to copy property from: "))
(setq sel2 (entsel "\n Select item to copy property to: "))

(setq data (entget (car sel)))
; not sure linetype number anymore, so we shall assume 8
(setq lt (cdr (assoc 8 data)))
(if (setq pos (vl-string-position lt "|"))
  (setq lt (substr lt pos))
)

(setq data (entget (car sel2)))
(entmod (subst (cons 8 lt) (assoc 8 data) data))
; maybe an update is needed
(entupd (cdr (assoc -1 data)))
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Match Properties from nested item.. is it possible?
« Reply #4 on: March 02, 2017, 09:21:18 AM »
Maybe this:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:mpn (/ e p s p p2)
  2.   (if (and (setq e (car (nentsel "\nPick an item to match property: "))) (setq s (ssget ":L")))
  3.     (progn (foreach prop '(6 62)
  4.              (if (or (setq p (assoc prop (entget e)))
  5.                      (setq p (assoc prop (entget (tblobjname "layer" (cdr (assoc 8 (entget e)))))))
  6.                  )
  7.                (setq p2 (cons p p2))
  8.              )
  9.            )
  10.            (foreach item (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  11.              (foreach prop p2 (entmod (append (entget item) (list prop))))
  12.            )
  13.     )
  14.   )
  15.   (princ)
  16. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Match Properties from nested item.. is it possible?
« Reply #5 on: March 02, 2017, 09:29:27 AM »
.. very interesting solution ronjonp, thank you, but unfortunately not completed
function change only colour of line acoording to colour of nested item, but linetype, layer name and other properties not changed yet

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Match Properties from nested item.. is it possible?
« Reply #6 on: March 02, 2017, 09:39:37 AM »
.. very interesting solution ronjonp, thank you, but unfortunately not completed
function change only colour of line acoording to colour of nested item, but linetype, layer name and other properties not changed yet




"For example to change linetype and color of selected line same to line from xref.."
It should do linetype and color like you asked for. If you don't do properties by object, all you have to do is put the new items on the same layer.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Match Properties from nested item.. is it possible?
« Reply #7 on: March 02, 2017, 09:50:19 AM »
It should do, but unfortunately don't :yes:
I checked it twice, but only colour changed..
Probably it will be more efficiently if you can program my first 3 steps:

1. Ncopy line from xref to current drawing
2. matchprop "ncopied" line to line I need to change
3. erase "ncopied" line



danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)

ahsattarian

  • Newt
  • Posts: 113
Re: Match Properties from nested item.. is it possible?
« Reply #9 on: July 26, 2022, 11:05:03 AM »
Try this  :




Code - Auto/Visual Lisp: [Select]
  1. (defun c:a ()
  2.   (setq es (entsel "\n Select Object inside Block : "))
  3.   (setq s (car es))
  4.   (setq po (cadr es))
  5.   (setq en (entget s))
  6.   (setq typ (strcase (cdr (assoc 0 en)) t))
  7.   (cond
  8.     ((= typ "insert")
  9.      (command "ncopy" po "" "none" '(0 0 0) "none" '(0 0 0))
  10.      (setq s1 (entlast))
  11.      (defun *error* (msg) (entdel s1) (princ))
  12.      ;;(command "matchprop" (nentselp po))
  13.      (command "matchprop" s1)
  14.      (while (> (getvar 'cmdactive) 0) (command "box" pause pause))
  15.      (entdel s)
  16.     )
  17.   )
  18.   (princ)
  19. )




ronjonp

  • Needs a day job
  • Posts: 7531
Re: Match Properties from nested item.. is it possible?
« Reply #10 on: July 26, 2022, 11:39:40 AM »
Try this  :
Code - Auto/Visual Lisp: [Select]
  1. (defun c:a ()
  2.   (setq es (entsel "\n Select Object inside Block : "))
  3.   (setq s (car es))
  4.   (setq po (cadr es))
  5.   (setq en (entget s))
  6.   (setq typ (strcase (cdr (assoc 0 en)) t))
  7.   (cond
  8.     ((= typ "insert")
  9.      (command "ncopy" po "" "none" '(0 0 0) "none" '(0 0 0))
  10.      (setq s1 (entlast))
  11.      (defun *error* (msg) (entdel s1) (princ))
  12.      ;;(command "matchprop" (nentselp po))
  13.      (command "matchprop" s1)
  14.      (while (> (getvar 'cmdactive) 0) (command "box" pause pause))
  15.      (entdel s)
  16.     )
  17.   )
  18.   (princ)
  19. )
That will not select an item within a block you have to use NENTSEL.

I've mentioned this to you multiple times, you should localize your variables ... especially the *error* function...
Code - Auto/Visual Lisp: [Select]
  1. (defun c:a (/ *error* en es po s s1 typ)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ahsattarian

  • Newt
  • Posts: 113
Re: Match Properties from nested item.. is it possible?
« Reply #11 on: December 31, 2023, 02:40:05 PM »
Try this  :
Code - Auto/Visual Lisp: [Select]
  1. (defun c:a ()
  2.   (setq es (entsel "\n Select Object inside Block : "))
  3.   (setq s (car es))
  4.   (setq po (cadr es))
  5.   (setq en (entget s))
  6.   (setq typ (strcase (cdr (assoc 0 en)) t))
  7.   (cond
  8.     ((= typ "insert")
  9.      (command "ncopy" po "" "none" '(0 0 0) "none" '(0 0 0))
  10.      (setq s1 (entlast))
  11.      (defun *error* (msg) (entdel s1) (princ))
  12.      ;;(command "matchprop" (nentselp po))
  13.      (command "matchprop" s1)
  14.      (while (> (getvar 'cmdactive) 0) (command "box" pause pause))
  15.      (entdel s)
  16.     )
  17.   )
  18.   (princ)
  19. )
That will not select an item within a block you have to use NENTSEL.

I've mentioned this to you multiple times, you should localize your variables ... especially the *error* function...
Code - Auto/Visual Lisp: [Select]
  1. (defun c:a (/ *error* en es po s s1 typ)


Hello Ronjonp

It WORKS.   It solved the Nentsel Problem, using  NCOPY in a better and more simple way.

Also Localizing is not so necessary.    It causes no problem.

Regards,   Amir

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Match Properties from nested item.. is it possible?
« Reply #12 on: January 01, 2024, 12:24:40 PM »
My Match Properties might be helpful.
Just change the entsel to nentsel .
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Match Properties from nested item.. is it possible?
« Reply #13 on: January 01, 2024, 06:55:14 PM »
Also Localizing is not so necessary.    It causes no problem.

Not true.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2150
  • class keyThumper<T>:ILazy<T>
Re: Match Properties from nested item.. is it possible?
« Reply #14 on: January 01, 2024, 10:46:00 PM »

Also Localizing is not so necessary.    It causes no problem.

Regards,   Amir

Not localising the *error* handler is Not correct

The error handler should be designed specifically for the function it is written in OR make use of a global handler.
By not localising the handler in a method you are forcing it to be global, where it will overwrite the current global handler that the user relys on.
This is not professional, in fact it is rude.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.