Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp - GROUP name = DWG name

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
m_rogoff
741 Views, 12 Replies

Lisp - GROUP name = DWG name

I have a simple string to GROUP all objects in a drawing. I would like to match the GROUP name with the DWG name (but not actually have ".dwg" in the name of the group). So Dwg "BLOCK.DWG" has a Group name "BLOCK" 

 

(command "-group" "n" "DWG NAME HERE" "" "all" "")

 

 

I want the pick point at 0,0. I can't find a way to define the pick point of a group (?)  It seems to center the pickpoint on the objects defined in the group. How do I keep the GROUP pickpoint at 0,0?

 

Thanks

 

 

12 REPLIES 12
Message 2 of 13
stevor
in reply to: m_rogoff

For the "DWG NAME HERE", use:

   (getvar 'dwgname)

 

For the group point, try "0,0".

 

A group of all is mysterious.

S
Message 3 of 13
hgasty1001
in reply to: m_rogoff

Hi,

 

Groups hasn't a pick point, the have grip at the center of the grouped objects (the center of the extent of the grouped objects), to show that grip, you need to set PICKSTYLE system variable in the range 1-3. About the name of the drawing, you can get the name only (without extension) with:

 

(substr (setq dwgname (getvar "dwgname")) 1 (- (strlen dwgname) 4))

 

Gaston Nunez

 

 

Message 4 of 13
MRogoff
in reply to: hgasty1001

Gaston,

 

I get this error message and the routine craps out

 

 

Enter a group name or [?]: (substr (setq dwgname (getvar *Invalid*
; error: Function cancelled
Enter a group name or [?]: 

Message 5 of 13
hmsilva
in reply to: MRogoff

The problem is not from Gaston's code, is from your prompt sequence...

 

Try

(command "-group" "_C" (substr (setq dwgname (getvar "dwgname")) 1 (- (strlen dwgname) 4)) "" "all" "")
;; or
(vl-load-com)
(command "-group" "_C" (vl-filename-base (getvar "dwgname")) "" "all" "")

 

Henrique

EESignature

Message 6 of 13
m_rogoff
in reply to: hmsilva

Henrique, that works great! Thanks!

 

One more thing please. I cannot figure out why this won't ungroup objects. Thanks

 

(command “UNGROUP” “all” “y”)

Message 7 of 13
hmsilva
in reply to: m_rogoff

You're welcome, m_rogoff.

 

I'm without AutoCAD, so untested, but try:

(command "_.ungroup" "all")
  (while (> (getvar 'cmdactive) 0)
    (command "Y")
  )

 

Henrique

 

 

EESignature

Message 8 of 13
m_rogoff
in reply to: hmsilva

Henrique, you are the man!

Message 9 of 13
hmsilva
in reply to: m_rogoff

I'm glad it worked

Henrique

EESignature

Message 10 of 13
m_rogoff
in reply to: stevor

Stevor,

 

   Let me elaborate on your point "A group of all is mysterious".

 

   I have objects inside of a block grouped into a single group. When you insert the block, it comes in on pre-defined layers. Once the block is exploded, you are left with a group of the objects with the same name as the block. Now the user can define the layer properties as needed. Hope this explains the Mystery. 

Message 11 of 13
m_rogoff
in reply to: hmsilva

Henrique,

 

   Sorry to bother you again, but I am having trouble with this lisp. It runs fine with ACad open and run independently. However, I have a batch routine that prompts a script, which loads and runs this lisp. Then it closes ACad and re-opens the next file in the folder and runs the script and lisp again. The lisp command is failing when run as part of the entire batch routine. Please advise. Lisp is attached. Thanks

 

THIS IS COMMAND LINE WHEN RUN INDEPENDENTLY

Command: _.ungroup
Select group or [Name]: all
Explode 1 groups? [Yes/No] <N>: Y
1 groups exploded.
Command: nil

 

 

WHEN RUN AS PART THE BATCH ROUTINE

Command: _.ungroup
Select group or [Name]: all
Explode 1 groups? [Yes/No] <N>: Y
1 groups exploded.
Command: Y Unknown command "Y". Press F1 for help.
Command: nil
Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:

Command: *Cancel*

Message 12 of 13
hmsilva
in reply to: m_rogoff

Hi m_rogoff,

 

I have no AutoCAD with me at the moment, therefore fully untested...

 

(vl-load-com)
(defun C:HARDWARE (/ groups)
(command "-layer" "s" "0" "")
(command "_.chprop" "all" "" "layer" "0" "c" "bylayer" "lw" "bylayer" "")
(if (setq groups (vla-get-groups (vla-get-activedocument (vlax-get-acad-object))))
  (vlax-for group groups
    (command "_.ungroup" "_N" (vla-get-name group))
  )
)
(princ)
)

 

Hope that helps

Henrique

EESignature

Message 13 of 13
hmsilva
in reply to: m_rogoff

In the above code, change

(if (setq groups (vla-get-groups (vla-get-activedocument (vlax-get-acad-object))))

 to

(if (and (setq groups (vla-get-groups (vla-get-activedocument (vlax-get-acad-object))))
         (> (vla-get-count groups) 0)
    )

 

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost