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

Help to code this lisp

5 REPLIES 5
Reply
Message 1 of 6
asos2000
448 Views, 5 Replies

Help to code this lisp

I want to code this lisp. So can some help me just the steps and commands i'll do the rest

The problem which I face is, In some drawings which come from the client, there are a lot of blocks.
I want to detect the blocks which has no sub-entities (but attribute) and add a rectangle inside this block, If it is an attribute add a line from 0,0, to insertpoint of attribute.

Thanks

5 REPLIES 5
Message 2 of 6
hmsilva
in reply to: asos2000

asos2000,

try

 

(defun c:test ()
  (if (setq ss (ssget "_X" '((0 . "INSERT")))) ; select all blocks
    (progn
      (setq itm	0 num (sslength ss))
      (while (< itm num)
	(setq hnd (ssname ss itm)
      	      ent (entget hnd))
	(IF (= (cdr (assoc 66 ent)) 1); if Attrib
	  (command "line" "_non" "0,0,0" "_non"  (cdr (assoc 10 ent)) ""); draw line
	  (progn; if not Attrib
	    (vla-getboundingbox (vlax-ename->vla-object hnd) 'minpoint 'maxpoint); get boundingbox
	    (setq pt_lst (list (vlax-safearray->list minpoint) (vlax-safearray->list maxpoint))); get points in list
	    (command "rectangle" "_non" (car pt_lst) "_non" (cadr pt_lst)); draw Rectangle
	  ); progn
	); if
	(setq itm (1+ itm))
      ); while
    );progn
  ); if
); test

 Cheers

Henrique

EESignature

Message 3 of 6
asos2000
in reply to: hmsilva

Thanks hmsilva for your quick reply

 

PLease find attached a file has sa sample of 2 blocks 

one has no objects this blocks i want to draw a rectangle inside - (lets say 1000x1000)

another one has attribute only

 

If no objects draw a rectangle inside the block

if att only draw a line from 0,0 of the block to inspoint of any att inside the block too

 

Regards

Message 4 of 6
Kent1Cooper
in reply to: asos2000


@asos2000 wrote:

....

The problem which I face is, In some drawings which come from the client, there are a lot of blocks.
I want to detect the blocks which has no sub-entities (but attribute) and add a rectangle inside this block, If it is an attribute add a line from 0,0, to insertpoint of attribute.
....

 

PLease find attached a file has sa sample of 2 blocks 

one has no objects this blocks i want to draw a rectangle inside - (lets say 1000x1000)

another one has attribute only

 

If no objects draw a rectangle inside the block

if att only draw a line from 0,0 of the block to inspoint of any att inside the block too


Some questions:

 

In your sample drawing, it appears you want the Line, drawn from 0,0 to an Attribute insertion point, to become a part of the Block definition.  It looks like hmsilva's routine would not do that, but would draw the Line independent of the Block.  Does it matter which way that is done?  [Independent is certainly easier.]

 

It's hard to imagine what a rectangle "inside" a Block with no sub-entities would be like -- should it be, for example, centered around the Block's insertion point [and therefore actually "outside" it]?  Drawing it around the bounding box as in hmsilva's routine would, I think, result in a zero-extent rectangle if the Block has no sub-entities [visually, a point, but not one that can be made easier to find with a PDMODE setting].  And should the rectangle become a part of the Block definition, or can it be independent?  If it's part of the definition, it will make multiple such Blocks visible, but maybe you never have more than one.

 

It also looks as though hmsilva's routine would draw a Line to the insertion point of the Block itself, rather than to the insertion point of an Attribute in the Block.  And it looks as though it would draw a Line from 0,0 to the insertion point of any Block containing Attributes, whether or not it also contains any other sub-entities, and would draw a rectangle around the bounding box of any Block without Attributes, whether or not it contains anything else.  I don't think those are what you're asking for, but a confirmation would be helpful.

Kent Cooper, AIA
Message 5 of 6
dgorsman
in reply to: asos2000

A basic, but non-code dependant, solution: ATTDISP command.

 

Out of curiosity... AF/AF-BASE, AO/AO-BASE, and/or VAL_BLK blocks?

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 6 of 6
asos2000
in reply to: dgorsman

Try this code

(defun c:revealblocks ( / doc lst )
;;-------------------------------------------;;
;;  Author: Lee Mac, - www.lee-mac.com       ;;
;;-------------------------------------------;;

    (vlax-for blk (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
        (if
            (and
                (= :vlax-false (vla-get-islayout blk))
                (= :vlax-false (vla-get-isxref blk))
                (null (wcmatch (vla-get-name blk) "`**"))
            )
            (progn
                (setq lst nil)
                (vlax-for obj blk (setq lst (cons obj lst)))
                (cond
                    (   (null lst)
                        (vla-put-closed
                            (vlax-invoke blk 'addlightweightpolyline
                               '(0.0 0.0 1000.0 0.0 1000.0 1000.0 0.0 1000.0)
                            )
                            :vlax-true
                        )
                    )
                    (   (vl-every '(lambda ( x ) (= "AcDbAttributeDefinition" (vla-get-objectname x))) lst)
                        (foreach att lst
                            (vlax-invoke blk 'addline '(0.0 0.0 0.0) (vlax-get att 'insertionpoint))
                        )
                    )
                )
            )
        )
    )
    (vla-regen doc acallviewports)
    (princ)
)
(vl-load-com) (princ)

 

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

Post to forums  

Autodesk Design & Make Report

”Boost