Author Topic: Entity multi object in group function  (Read 3290 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Entity multi object in group function
« on: March 18, 2008, 07:45:21 PM »
Hi Alls,
I got problem to solve my code, in function group can not accepted with multi entity, any one know to solve my problem,thanks.

Code: [Select]
(defun c:gww (/ col cor des el lst name p1 p2 pte vevo)
  (setq p1 (getpoint "\nPick any location: "))
  (while
    (setq p2 (getpoint p1 "\nPick as end location: "))
    (command "_pline" p1 p2 "" "")
    (setq el (entlast))
    (setq col (getint "\nEnter new value color: "))
    (command "_change" el "" "p" "c" col "")
    (setq vevo (vlax-ename->vla-object el))   
    (setq cor (vlax-get vevo 'Coordinates))
    (setq pte (list (nth 2 cor)(nth 3 cor)))
    (setq p1 pte)
    (setq lst (append lst (list el)))
    ) ; while
  (setq name (getstring "\nEnter a group name<Sample>: "))
  (if (= name "")(setq name "Sample")) 
  (setq des (getstring "\nEnter a group description<Polyline multi color>: "))
  (if (= des "")(setq des "Polyline multi color"))
  (command "_group" "c" name des lst "")
  (princ)
  )   ; defun
« Last Edit: March 18, 2008, 07:53:28 PM by Adesu »

daron

  • Guest
Re: Entity multi object in group function
« Reply #1 on: March 18, 2008, 08:47:51 PM »
The problem is a little cryptic. Could you put up the idea and steps involved for getting from point A to point B. This is kinda like being shown the finish line in a race without being given a map of how to run the race.

BTW, Just out of curiosity; what is your native language?

Adesu

  • Guest
Re: Entity multi object in group function
« Reply #2 on: March 18, 2008, 09:20:26 PM »
Hi Daron,
Here a sample dwg, see attach file


"Just out of curiosity; what is your native language?"

Yes my English very poor and bad....sorry, I'm from Indonesia.
« Last Edit: March 18, 2008, 09:32:57 PM by Adesu »

gile

  • Water Moccasin
  • Posts: 2400
  • Marseille, France
Re: Entity multi object in group function
« Reply #3 on: March 19, 2008, 03:11:55 AM »
Hi,

Here're some routines to create or delete anonymous groups.
PS:  these groups appear as GRP1, GRP2, etc... instead of *A1, *A2, etc...

Code: [Select]
;; MAKEGROUP
;; Creates an anonymous group from an entity list
;;
;; Argument
;; lst : entity list (ename)
;;
;; Return
;; The created group (ename) or nil

(defun makegroup (lst / dict ind)
  (setq dict (dictsearch (namedobjdict) "ACAD_GROUP")
ind "GRP1")
  (while (member (cons 3 ind) dict)
    (setq ind (strcat "GRP" (itoa (1+ (atoi (substr ind 4))))))
  )
  (dictadd
    (cdr (assoc -1 dict))
    ind
    (entmakex
      (append
(list
  '(0 . "GROUP") '(100 . "AcDbGroup") '(300 . "") '(70 . 1) '(71 . 1))
(mapcar (function (lambda (x) (cons 340 x))) lst)
      )
    )
  )
)

;; DELGROUP
;; Deletes all groups which the entity belongs to.
;;
;; Argument
;; ent : the entity name (ename)
;;
;; Return
;; The deleted groups list or nil

(defun delgroup (ent / ret)
  (mapcar
    (function
      (lambda (p)
(and
  (= (car p) 330)
  (= (cdr (assoc 0 (entget (cdr p)))) "GROUP")
  (setq ret (cons (entdel (cdr p)) ret))
)
      )
    )
    (entget ent)
  )
  ret
)

;; PURGEGROUP
;; Deletes all empty groups

(defun purgegroup ()
  (foreach g (mapcar 'cdr
     (vl-remove-if-not
       (function
(lambda (x) (= (car x) 350))
       )
       (dictsearch (namedobjdict) "ACAD_GROUP")
     )
     )
    (or (assoc 340 (entget g)) (entdel g))
  )
)

;; GRP
;; Creates a group with selected objects

(defun c:grp (/ ss n lst)
  (and
    (setq ss (ssget))
    (repeat (setq n (sslength ss))
      (setq lst (cons (ssname ss (setq n (1- n))) lst))
    )
    (makegroup lst)
  )
  (princ)
)

;; DGRP
;; Deletes all groups which the selected object belongs to.

(defun c:dgrp (/ ent)
  (and
    (setq ent (car (entsel)))
    (delgroup ent)
  )
  (princ)
)
Speaking English as a French Frog

Adesu

  • Guest
Re: Entity multi object in group function
« Reply #4 on: March 19, 2008, 04:56:19 AM »
Hi gile,
first said thanks for your code.
after I tested your code with combine my code, it still got problem, look like this reported.
Code: [Select]
Enter a group description<Polyline multi color>:
_group Enter a group option
[?/Order/Add/Remove/Explode/REName/Selectable/Create] <Create>: c
Enter a group name or [?]: Sample Enter a group description: Polyline multi
color
Select objects: <Bad Entity name: 7EB52600>
Select objects: Specify opposite corner: 5 found, 1 group
Select objects:

My question is why still displayed select object function, in my opinion with your code added to my code, it should more practice.
here new code

Code: [Select]
(defun makegroup (lst / dict ind)  ; by gile
  (setq dict (dictsearch (namedobjdict) "ACAD_GROUP"))
  (setq ind "GRP1") 
  (while
    (member (cons 3 ind) dict)
    (setq ind (strcat "GRP" (itoa (1+ (atoi (substr ind 4))))))
  ) ; while
  (dictadd
    (cdr (assoc -1 dict))
    ind
    (entmakex
      (append
(list '(0 . "GROUP") '(100 . "AcDbGroup") '(300 . "") '(70 . 1) '(71 . 1))
(mapcar (function (lambda (x) (cons 340 x))) lst)
) ; append
      )   ; entmakex
    )     ; dictadd
  )       ; defun

(defun c:gww (/ col cor des el lst name p1 p2 pte ss vevo)
  (setq p1 (getpoint "\nPick any location<0,0,0>: "))
  (if (= p1 nil)(setq p1 '(0 0 0)))
  (while
    (setq p2 (getpoint p1 "\nPick as end location: "))
    (command "_pline" p1 p2 "" "")
    (setq el (entlast))
    (setq col (getint "\nEnter new value color: "))
    (command "_change" el "" "p" "c" col "")   
    (setq vevo (vlax-ename->vla-object el))
    ;(vlax-dump-object vevo)
    (setq cor (vlax-get vevo 'Coordinates))
    (setq pte (list (nth 3 cor)(nth 4 cor)(nth 5 cor)))
    (setq p1 pte)
    (setq lst (append lst (list el)))
    ) ; while
  (setq name (getstring "\nEnter a group name<Sample>: "))
  (if (= name "")(setq name "Sample")) 
  (setq des (getstring "\nEnter a group description<Polyline multi color>: "))
  (if (= des "")(setq des "Polyline multi color"))
  (setq ss (makegroup lst))
  (command "_group" "c" name des ss "")
  (princ)
  )   ; defun


Hi,

Here're some routines to create or delete anonymous groups.
PS:  these groups appear as GRP1, GRP2, etc... instead of *A1, *A2, etc...

Code: [Select]
;; MAKEGROUP
;; Creates an anonymous group from an entity list
;;
;; Argument
;; lst : entity list (ename)
;;
;; Return
;; The created group (ename) or nil

(defun makegroup (lst / dict ind)
  (setq dict (dictsearch (namedobjdict) "ACAD_GROUP")
ind "GRP1")
  (while (member (cons 3 ind) dict)
    (setq ind (strcat "GRP" (itoa (1+ (atoi (substr ind 4))))))
  )
  (dictadd
    (cdr (assoc -1 dict))
    ind
    (entmakex
      (append
(list
  '(0 . "GROUP") '(100 . "AcDbGroup") '(300 . "") '(70 . 1) '(71 . 1))
(mapcar (function (lambda (x) (cons 340 x))) lst)
      )
    )
  )
)

;; DELGROUP
;; Deletes all groups which the entity belongs to.
;;
;; Argument
;; ent : the entity name (ename)
;;
;; Return
;; The deleted groups list or nil

(defun delgroup (ent / ret)
  (mapcar
    (function
      (lambda (p)
(and
  (= (car p) 330)
  (= (cdr (assoc 0 (entget (cdr p)))) "GROUP")
  (setq ret (cons (entdel (cdr p)) ret))
)
      )
    )
    (entget ent)
  )
  ret
)

;; PURGEGROUP
;; Deletes all empty groups

(defun purgegroup ()
  (foreach g (mapcar 'cdr
     (vl-remove-if-not
       (function
(lambda (x) (= (car x) 350))
       )
       (dictsearch (namedobjdict) "ACAD_GROUP")
     )
     )
    (or (assoc 340 (entget g)) (entdel g))
  )
)

;; GRP
;; Creates a group with selected objects

(defun c:grp (/ ss n lst)
  (and
    (setq ss (ssget))
    (repeat (setq n (sslength ss))
      (setq lst (cons (ssname ss (setq n (1- n))) lst))
    )
    (makegroup lst)
  )
  (princ)
)

;; DGRP
;; Deletes all groups which the selected object belongs to.

(defun c:dgrp (/ ent)
  (and
    (setq ent (car (entsel)))
    (delgroup ent)
  )
  (princ)
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Entity multi object in group function
« Reply #5 on: March 19, 2008, 05:14:33 AM »

I would have liked to help, but I can't understand the problem.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Adesu

  • Guest
Re: Entity multi object in group function
« Reply #6 on: March 19, 2008, 05:27:37 AM »
Hi Kerry,
if you run my code, at the group function, I want the user don't get order to select object, because the alls object has create become one entity (makegroup) with gile code.
I hope my information more clear, sorry if you become confuse
any idea for it.


I would have liked to help, but I can't understand the problem.

gile

  • Water Moccasin
  • Posts: 2400
  • Marseille, France
Re: Entity multi object in group function
« Reply #7 on: March 19, 2008, 06:10:22 AM »
Adesu,

The makegroup routine is to create an anonymous group from an entity list.
I revised your code using a new routine 'MakeNamedGroup'.
I add it a test to see if the named group doesn't already exist.
NOTE: Your routine doesn't work if PLINETYPE is different from 0.

EDIT: corrected the test about already same named group

Code: [Select]
;; MAKENAMEDGROUP
;; Creates an named groupe from an enames list
;;
;; Arguments
;; name : the group name (string)
;; descr : the group description (string)
;; lst : enames list
;;
;; Return
;; The created group ename or nil if failed

(defun MakeNamedGroup (name descr lst / dict)
  (setq dict (dictsearch (namedobjdict) "ACAD_GROUP"))
  (if (null (member (cons 3 (strcase name)) dict))
    (dictadd
      (cdr (assoc -1 dict))
      name
      (entmakex
(append
  (list '(0 . "GROUP")
'(100 . "AcDbGroup")
(cons 300 descr)
'(70 . 0)
'(71 . 1)
  )
  (mapcar (function (lambda (x) (cons 340 x))) lst)
)
      )
    )
  )
)

(defun c:gww (/ col cor des el lst name p1 p2 pte ss vevo)
  (setq p1 (getpoint "\nPick any location<0,0,0>: "))
  (if (= p1 nil)
    (setq p1 '(0 0 0))
  )
  (while
    (setq p2 (getpoint p1 "\nPick as end location: "))
     (command "_pline" p1 p2 "" "")
     (setq el (entlast))
     (setq col (getint "\nEnter new value color: "))
     (command "_change" el "" "_p" "_c" col "")
     (setq vevo (vlax-ename->vla-object el))
;(vlax-dump-object vevo)
     (setq cor (vlax-get vevo 'Coordinates))
     (setq pte (list (nth 3 cor) (nth 4 cor) (nth 5 cor)))
     (setq p1 pte)
     (setq lst (append lst (list el)))
  ) ; while
  (setq name (getstring "\nEnter a group name <Sample>: "))
  (if (= name "")
    (setq name "Sample")
  )
  (while (member (cons 3 (strcase name))
(dictsearch (namedobjdict) "ACAD_GROUP")
)
    (princ (strcat "\nGroup \"" name "\" already exists. "))
    (setq name (getstring "Enter a group name: "))
  )
  (setq des (getstring T
      "\nEnter a group description<Polyline multi color>: "
    )
  )
  (if (= des "")
    (setq des "Polyline multi color")
  )
  (MakeNamedGroup name des lst)
  (princ)
) ; defun
« Last Edit: March 19, 2008, 08:49:55 AM by gile »
Speaking English as a French Frog

daron

  • Guest
Re: Entity multi object in group function
« Reply #8 on: March 19, 2008, 11:49:37 AM »
Hi Daron,
Here a sample dwg, see attach file


"Just out of curiosity; what is your native language?"

Yes my English very poor and bad....sorry, I'm from Indonesia.
Not what I asked. What is your native language, not where are you from? I don't know what language Indonesians speak. Your English is good. The real problem was as Kerry stated:

I would have liked to help, but I can't understand the problem.
and as I tried to imply in my initial posting. However, I do get the concept of what you're trying to accomplish. It seems that you want to be able to have a polyline with different colors. The idea is neat. I pondered that years ago, as I'm sure others have too. Your bringing it up again has made me think, but instead of a group I'm wondering if we can't make a custom object either with lisp or .net that would allow one to create a collection of lines with a rebuilt polyline ?stack? containing the collection and making it appear as though it were a polyline. Creating polylines linked together and grouped as a whole is not a good route to take, IMO. Groups are too "dynamic" if you will. That said, it's not something I have great need of, so I won't be of much help. Thanks for bringing up the idea and getting those old synapses going again.

Adesu

  • Guest
Re: Entity multi object in group function
« Reply #9 on: March 23, 2008, 08:37:15 PM »
Hi Daron,
I think you should know(sorry).
Country= Indonesia,language = Indonesia
and
Country/language = Japan
Country/language = Korea
etc....


Quote
What is your native language

daron

  • Guest
Re: Entity multi object in group function
« Reply #10 on: March 24, 2008, 11:19:09 AM »
Thank you.
Quote
Country/language = Japan
Country/language = Korea
etc....
Not true of all languages. Where do the people who speak Urdu come from? Not the country of Urd. Plus, most people speak a dialect of their country's language based on their region. Take China for example. We refer to their language as Chinese, but mainland China speaks Mandarin while others speak Canotnese or various other dialects.

Anyway, to bring some relevance to the topic, I wondered in case there was someone capable of translating your language into English to better convey your messages in the future; I don't know anyone who speaks Indonesian, but keep asking questions and bettering you English. Immersion is the best form of learning. Who knows, if you feel like throwing in a word or two in Indonesian we might also learn something as well.