Author Topic: dynamic blocks  (Read 8823 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: dynamic blocks
« Reply #15 on: December 28, 2010, 05:22:04 PM »
i'm not sure if ssget always return list object from last to first in drawing base. can someone confirm that?

Not reliable. Sort the entities by their handle (converted to an integer) or ObjectID prior to indexing.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kruuger

  • Swamp Rat
  • Posts: 633
Re: dynamic blocks
« Reply #16 on: December 28, 2010, 05:43:24 PM »
i'm not sure if ssget always return list object from last to first in drawing base. can someone confirm that?

Not reliable. Sort the entities by their handle (converted to an integer) or ObjectID prior to indexing.
Thanks MP. I will keep in mind this.

kruuger

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: dynamic blocks
« Reply #17 on: December 28, 2010, 06:37:07 PM »
Some quick code / food for thought:

PicksetToObjects:
Code: [Select]
(defun _PicksetToObjects ( ss )

    [color=green];;  Convert a pickset (selection set) to a list of objects.[/color]

    (if (eq 'pickset (type ss))
        (mapcar
            (function (lambda (x) (vlax-ename->vla-object (cadr x))))
            (vl-remove-if (function (lambda (x) (minusp (car x)))) (ssnamex ss))
        )
    )
)

SortObjects:
Code: [Select]
(defun _SortObjects ( objects foo )

    [color=green];;  Sort the objects using function foo, which takes two
    ;;  arguments, both objects. What foo does we don't care,
    ;;  our job is to invoke it if it's defined. Note: define
    ;;  foo using the (function (lambda (a b) ...)) form. If
    ;;  foo is not defined sort the objects by the ObjectIDs.[/color]
    
    (vl-sort objects
        (if [color=red]foo foo[/color]
            (function
                (lambda (a b)
                    (<
                        (vla-get-objectid a)
                        (vla-get-objectid b)
                    )
                )
            )
        )      
    )
)

Demo:
Code: [Select]
(if (setq objects ([color=red]_PicksetToObjects[/color] (ssget)))
    (progn
        (princ "\n\nObjectIDs for the unsorted list:")
        (print (mapcar 'vla-get-objectid objects))
        (princ "\n\nObjectIDs for the sorted list, default algorythm:")
        (print (mapcar 'vla-get-objectid ([color=red]_SortObjects[/color] objects nil)))
        (princ "\n\nObjectIDs for the sorted list, custom algorythm:")
        (print
            (mapcar 'vla-get-objectid
                ([color=red]_SortObjects[/color] objects
                    (function
                        (lambda (a b)
                            (<
                                (vla-get-objectname a)
                                (vla-get-objectname b)
                            )
                        )
                    )      
                )
            )
        )
        (princ)
    )
)

Output:
Code: [Select]
ObjectIDs for the unsorted list:
(51 50 49 48 46 43 52 53 54 55 56 57 58 59 60)

ObjectIDs for the sorted list, default algorithm:
(43 46 48 49 50 51 52 53 54 55 56 57 58 59 60)

ObjectIDs for the sorted list, custom algorithm:
(54 55 59 56 43 51 50 49 48 46 57 52 53 60 58)
« Last Edit: December 28, 2010, 06:43:14 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

pBe

  • Bull Frog
  • Posts: 402
Re: dynamic blocks
« Reply #18 on: December 29, 2010, 03:02:37 AM »
Looks like you guys got it all covered

I would have done it the same way as kruuger's but slightly different


Code: [Select]
(defun c:test ()
  (vl-load-com)
  (setq this-dwg (vla-get-activedocument (vlax-get-acad-object)))
(while (not (setq Mullion_block (ssget '((0 . "INSERT"))))))
  (cond (
(mapcar
          '(lambda (bl_sl)
(if
(/= (vla-get-EffectiveName
                      (vlax-ename->vla-object bl_sl)) "Mullion")
  (ssdel bl_sl Mullion_block)))
         (vl-remove-if 'listp
                (mapcar 'cadr(ssnamex Mullion_block))))
         
        (setq cnt -1 row_nm (sslength mullion_block) pro_sel (ssadd))
        (while (setq mb_brp
                   (ssname  Mullion_block (setq cnt (1+ cnt))))
(setq mb_prop
          (vlax-invoke (setq mb_ss (vlax-ename->vla-object mb_brp)) 'GetDynamicBlockProperties))
                 
          (setq width_v (vlax-variant-value
                                (vla-get-value (nth 0 mb_prop)))
                     height_v (vlax-variant-value
                                (vla-get-value (nth 2 mb_prop)))
                )
          (vla-put-textstring
                  (car (vlax-invoke mb_ss 'Getattributes))
                  (strcat (rtos width_v 2 0) "x" (rtos height_v 2 0))
                )
          (setq pro_sel (ssadd mb_brp pro_sel))
          );while
          ;(pro pro_sel)<-- routine for sorting and counting the dyn blocks  would go here
          );
         )
    )

then after gathering data, create a table

Code: [Select]
(defun db_atv ()
(setq Mullion_table
  (vla-addtable  (vla-get-modelspace this-dwg) (vla-getpoint (vla-get-utility this-dwg) nil "\nPick point for Table:")
  (+ row_nm 2) 4 30 110))

  (vla-settext Mullion_table 0 0 "Mullion")
  (vla-settext Mullion_table 1 0 "Count")
  (vla-settext Mullion_table 1 1 "Block ID")
  (vla-settext Mullion_table 1 2 "Width")
  (vla-settext Mullion_table 1 3 "Height")
;;<--- code for assigning values (data  from the previous) sub would go here
  )


anyhoo.. the plan was sort and assign lowest number to the smallest duct and so on.....
i also thought of converting it to a Staticblock and assing a unique name for every block (Mullion_A, Mullion_B....)

oh well....

HasanCAD

  • Swamp Rat
  • Posts: 1421
Re: dynamic blocks
« Reply #19 on: December 29, 2010, 10:28:29 AM »
:-)
It works. THANKS!!!!
uff  :wink:

thanks
kruuger




Error in CAD2010

Code: [Select]
Command: AUTOID
; error: no function definition: VLAX-GET-ACAD-OBJECT

kruuger

  • Swamp Rat
  • Posts: 633
Re: dynamic blocks
« Reply #20 on: December 29, 2010, 10:34:51 AM »

Thomas 3D

  • Guest
Re: dynamic blocks
« Reply #21 on: January 06, 2011, 02:05:25 AM »
Good morning Kruuger,

I still have a question for you. I wanted to use your program for another drawing. I have implemented the ID attribut in a  new block. Then I have started your lisp routine.
Autocad said:

Befehl: autoid
; Fehler: Fehlerhafter Argumenttyp: lselsetp nil

What does that mean? Can I not use your lisp routine for other blocks?

Thomas

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: dynamic blocks
« Reply #22 on: January 06, 2011, 05:48:33 AM »
That message  indicates that a symbol has nil value where a value is expected.

If you load the code into the VLIDE, set menu dropdown Debug->BreakOnError to ON (ticked) then load the code from the VLIDE into Autocad.

When the code stops with an error select Debug->LastBreakSource or Ctrl-F9 to display the line the error is on.

Adding (vl-bt) to your error trap routine may also help locating the cause of an error.
something like this
Code: [Select]
[color=green];; errortrap.lsp[/color]
  [color=green];;-------------------------------------[/color]
  (defun [color=blue]*error*[/color] (msg)
    [color=green];;----- Cancel any Active Commands[/color]
    (while (< 0 (getvar [color=Maroon]"cmdactive"[/color])) (command))
    [color=green];;----- Display error message if applicable[/color]
    (cond ((not msg))
          ((member (strcase msg t) '([color=Maroon]"console break"[/color] [color=Maroon]"function cancelled"[/color] [color=Maroon]"quit / exit abort"[/color])))
          ((princ (strcat [color=Maroon]"\nApplication Error: "[/color] (itoa (getvar [color=Maroon]"errno"[/color])) [color=Maroon]" :- "[/color] msg))
           [color=green];;----- Display backtrace[/color]
           (vl-bt)
          )
    )
    (setvar [color=Maroon]"errno"[/color] 0)
    (princ)
  )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

kruuger

  • Swamp Rat
  • Posts: 633
Re: dynamic blocks
« Reply #23 on: January 06, 2011, 06:33:09 PM »
Hi Thomas
Do you want to use routine with new block name?
Did you change Mullion name in lisp to new name?
 Maybe you want select block first and then continue?
kruuger

Thomas 3D

  • Guest
Re: dynamic blocks
« Reply #24 on: January 07, 2011, 01:40:05 AM »
Hi Kruuger,

I want to use your lisp routine for a new drawing with new different block names.

I haven't changed the Mullion name in the lisp routine. Sorry, but I do not understand Lisp programming.

Certainly it would be nice if you could first select the blocks and then I start your routine. This would not be so important, because if I create a new block, than I can say that block gets the ID-Attribute or not. Is it a big hassle for you to change your routine to the effect?

Thomas

kruuger

  • Swamp Rat
  • Posts: 633
Re: dynamic blocks
« Reply #25 on: January 07, 2011, 02:51:42 AM »
ok, no problem. i try to incorporate this change to lisp + MP_ SortObject function
kruuger

kruuger

  • Swamp Rat
  • Posts: 633
Re: dynamic blocks
« Reply #26 on: January 07, 2011, 09:42:34 AM »
try this code. let me know if it works for you.
thanks MP. Sort function works perfect :)
kruuger

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: dynamic blocks
« Reply #27 on: January 07, 2011, 10:48:28 AM »
great to hear kruuger --- thanks for letting me know --- thanks for helping T3D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Thomas 3D

  • Guest
Re: dynamic blocks
« Reply #28 on: January 07, 2011, 04:05:04 PM »
Hi Kruuger,

Thank you for your quick help. I have tested your new lisp routine. Please look at my file. When I start the routine, then the first 2 blocks are not taken into account. Have you any idea why the program such react?

Thomas

kruuger

  • Swamp Rat
  • Posts: 633
Re: dynamic blocks
« Reply #29 on: January 07, 2011, 05:13:18 PM »
i found a small mistake. try now
kruuger