groups question

Discussion in 'AutoCAD' started by mark, Sep 13, 2004.

  1. mark

    mark Guest

    how to obtain a list of all object/entity names in a group,
    and how to add after an entmake,a new object to that group.

    TIA
     
    mark, Sep 13, 2004
    #1
  2. mark

    mark Guest

    actually i am interested in the second part of my question,
    the first can be obtained as follows, where ename is a valid
    entity name.

    (mapcar 'cdr
    (vl-remove-if-not
    (function (lambda (itm)(= (car itm) 340)))
    (entget (cdr (assoc 330 (entget ename))))) )
     
    mark, Sep 13, 2004
    #2
  3. mark

    andywatson Guest

    Here are two commands...
    ListGroupObjects - lists all defined groups and the handles of the objects contained within them
    CreateGroup - creates a group asking user for new group name and objects to group
    These are using ActiveX, no error-handling :)
    Code:
    ;; command to list all groups and their objects' handles
    (defun c:ListGroupObjects ( / acadDoc acadGroups acadGroup strName strTotal strHandle groupObj)
    ;; load activex
    (vl-load-com)
    ;; get autocad document and all defined groups
    (setq acadDoc (vla-get-activedocument (vlax-get-acad-object))
    acadGroups (vla-get-groups acadDoc)
    )
    ;; cycle through every group
    (vlax-for acadGroup acadGroups
    ;; get name of current group, total items in group
    (setq strName (vla-get-name acadGroup)
    strTotal (itoa (vla-get-count acadGroup))
    ); setq
    ;; display group name, total items
    (prompt (strcat "\nGroup: " strName "  Objects: " strTotal))
    (prompt "\n--------------------------------")
    ;; for every item in group
    (vlax-for groupObj acadGroup
    ;; get handle, display handle
    (setq strHandle (vla-get-handle groupObj))
    (prompt (strcat "\nHandle: " strHandle))
    ); vlax-for
    ;; two empty lines between every group
    (prompt "\n\n")
    ); vlax-for
    ;; release activex objects
    (mapcar 'vlax-release-object (list acadGroups acadDoc))
    ;; exit quietly
    (princ)
    ); defun
    ;;
    ;;
    ;; command to create a group
    (defun c:CreateGroup ( / ss vlass acadDoc acadGroups newGroup strName objArray ssCount index)
    ;; load activex
    (vl-load-com)
    ;; get autocad document and groups collection object
    (setq acadDoc (vla-get-activedocument (vlax-get-acad-object))
    acadGroups (vla-get-groups acadDoc)
    ); setq
    ;; if user enters a group name and selects objects...
    (cond
    ;; user does not enter a name
    ((= "" (setq strName (getstring "\nNew group name: ")))
    nil
    )
    ;; user enters name AND selects objects
    ((setq ss (ssget))
    ;; get activex selection set, number of objects selected,
    ;; prepare object array to store objects, create group, initialize index
    (setq ss (vla-get-activeselectionset acadDoc)
    ssCount (vla-get-count ss)
    objArray (vlax-make-safearray vlax-vbObject (cons 0 (1- ssCount)))
    newGroup (vla-add acadGroups strName)
    index 0
    ); setq
    ;; for every object in selection set
    (vlax-for obj ss
    ;; put object in array at index location
    (vlax-safearray-put-element objArray index obj)
    ;; increment index
    (setq index (1+ index))
    ); vlax-for
    ;; convert array to variant
    (vlax-make-variant objArray)
    ;; add objects to group
    (vla-appenditems newGroup objArray)
    ;; release activex objects
    (mapcar 'vlax-release-object (list newGroup acadGroups acadDoc))
    (prompt "\nDone.")
    )
    ;; user selects nothing
    (T
    (prompt "\nNothing selected.")
    )
    ); cond
    ;; exit quietly
    (princ)
    ); defun
    ;;
    ;;
    ;;
    ;; display command names upon load
    (prompt "\nType \"ListGroupObjects\" to list all defined groups and their objects.")
    (prompt "\nType \"CreateGroup\" to create a new group.")
    
     
    andywatson, Sep 13, 2004
    #3
  4. mark

    mark Guest

    thanks for the feedback,
    actually the entmod function works fine

    (setq ename1 (car (entsel))) ;; object within a group
    (setq ename2 (car (entsel))) ;; any new object

    (setq elist (entget (cdr (assoc 330 (entget ename1)))))
    (entmod (append elist (list (cons 340 ename2))))

    BUT i am not able to do it in a layout other than
    the current, i am trying to entmake objects in a
    layout other than the current (no problem)
    and then add it to an existing group on that same



     
    mark, Sep 14, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.