Jump to content

Block Counter (Includes Dynamic Blocks)


Lee Mac

Recommended Posts

  • Replies 131
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    58

  • The Buzzard

    7

  • autolisp

    5

  • piscopatos

    4

Top Posters In This Topic

Posted Images

Here is some code that is useful for dynamic blocks. I may have gotten this from here but I don't remember for sure.

;----------------------------------------------------------- DynamicProps -----
; Function retrieve or set properties from a dynamic block
; (DynamicProps (car (entsel)) "Visibility" nil) get the visibility states from a dynamic block
; (DynamicProps (car (entsel)) "Visibility" "Construction") set the visibility from a dynamic block
; (DynamicProps (car (entsel)) "" nil) get the properties from a dynamic block
; (DynamicProps (car (entsel)) "Pipe length" 2000.0) set the properties from a dynamic block
(defun DynamicProps (ename propname value / obj prpL cla cll prp)
 (setq obj (if (= (type ename) 'VLA-OBJECT) ename (vlax-ename->vla-object ename)))
 (setq prpL (vlax-invoke obj 'getdynamicblockproperties))
 (setq return
   (if (setq prp (vl-remove-if-not (function (lambda(x)(= (vlax-get-property x 'PropertyName) propname))) prpL))
     (mapcar (function (lambda(v)
       (if (and (/= value nil)(vlax-property-available-p v 'Value)(/= (type value)'LIST))
         (progn (vlax-put-property v 'Value value)(vla-update obj))
       )
       (if (and (vlax-property-available-p v 'AllowedValues) (vlax-get v 'AllowedValues))
         (list (vlax-get v 'Value)(vlax-get v 'AllowedValues))
  (vlax-get v 'Value)
       )
     )) prp)
     (mapcar (function (lambda(v)(list (vla-get-propertyName v)(vlax-get v 'Value) v))) prpL)
   )
 )
 return
)
;------------------------------------------------ MWE:GetDBlockNames ------------------
; Function for filtering dynamic blocks
; Arguments: 1
;    arglst = list met names
; Syntax: (MWE:GetDBlockNames '("Issue Stamp")) --> (("ISSUE STAMP" "*U833" "*U841") 
;function by James Allen.
;;; Returns all names used for a dynamic block, including
;;; the actual block name and all anonymous instances.
;;;
;;; (setq names (MWE:GetDBlockNames (list bname)))
;;;
;;; bname = Str - Dynamic block name
;;; names = List - List of all inserted blocks whose
;;; EffectiveName = bname
;;;
;;; (setq names (MWE:GetDBlockNames '("TestDBlock")))
;;; ("TestDBlock" "*U4" "*U5" "*U6")
;;;
;;; James Allen - 26Apr07
;;; Malicoat-Winslow Engineers, P.C.
;;;
;;; Thanks to Joe Burke for pointing out code 331
;;; and to Tony Tanzillo for prodding in that direction.
;;;
(defun MWE:GetDBlockNames (arglst / blk edt enm ins name names)
 (mapcar 'set '(name) arglst)
 (setq names (list name) name (strcase name))
 (vl-load-com)
 (vlax-for blk (vla-get-Blocks (vlax-get (vlax-get-Acad-Object) 'ActiveDocument))
   (if (and (setq enm (tblobjname "block" (vla-get-Name blk)))
     (setq edt (entget enm))
     (= (logand (cdr (assoc 70 edt)) 1) 1))
     (if (and (setq edt (entget (vlax-vla-object->ename blk)))
       (setq enm (cdr (assoc 331 edt)))
       (setq ins (vlax-ename->vla-object enm))
       (eq (vla-get-ObjectName ins) "AcDbBlockReference")
       (wcmatch (strcase (vla-get-EffectiveName ins)) name))
       (setq names (cons (vla-get-Name blk) names))
     )
   )
 )
 (reverse names)
) ;end
;------------------------------------------------ BlockNamesFilter ------------------
;; Argument example: ("TestDBlock" "*U4" "*U5" "*U6")
;; Returns: "TestDBlock,`*U4,`*U5,`*U6,"
(defun BlockNamesFilter (strlst)
 (apply 'strcat (mapcar '(lambda (x)
   (if (wcmatch x "`**,`?*")(strcat "`" x ",")(strcat x ","))) strlst)
 )
)
;----------------------------------------------------------- ChangeVisibility -----
;; Argument example: (ChangeVisibility "Issue Stamp" "Review")
;; Returns: number of changed states
(defun ChangeVisibility (BlkName state / names ss ssl tempEnt)
 (setq names (MWE:GetDBlockNames (list BlkName)))
 (if (and (setq ss (ssget "P" (list '(0 . "INSERT")(cons 2 (BlockNamesFilter names)))))
   (> (setq ssl (sslength ss)) 0))
   (progn
     (while (setq tempEnt (ssname ss 0))
(DynamicProps (vlax-ename->vla-object tempEnt) "Visibility" state)
       (ssdel tempEnt ss)
     )
     (princ (strcat "\nChanged "(itoa ssl) " inserts to the visibility <" state ">."))
     ssl
   )
   (princ (strcat "\nInsert " BlkName " not found."))
 )
)

Link to comment
Share on other sites

  • 1 month later...

hello

after this line: Table? [Yes/No/Settings] : y

i have error: ** Error: Too many actual parameters **

win7 64bit, autocad 2011 64bit, i use it on blocks with attributes

Link to comment
Share on other sites

Just tried it got the same result as spin

 

xf_D1...................................|.......5

xf_D1-b.................................|.......1

xf_D3...................................|.......1

xf_D4...................................|.......1

xf_DA...................................|.......2

xf_E....................................|.......1

xf_E-a..................................|.......1

xf_E1...................................|.......3

xf_EA...................................|.......1

xf_ED...................................|.......1

xf_ED-a.................................|.......1

xf_door_ext_FIX.........................|.......1

zf_216..................................|.......1

zf_PARAPETTO-108........................|.......2

----------------------------------------|--------

Table? [Yes/No/Settings] : y

** Error: Too many actual parameters **

 

The previous version is excellent.

Link to comment
Share on other sites

Hi Lee,

looks to be a great script. and if it produces a legend with pictures of blocks then I will be held in high regard at the office...ha ha.

 

but at the moment I also get the Too many actual parameters error as 'spin' got and when picking fewer blocks as a test i get an empty table.

 

AutoCAD 2011 win7 64 bit.

Link to comment
Share on other sites

Ok, Thanks for the reports guys - it looks to be a 64-bit issue. The methods for the table are different for 32-bit and 64-bit systems, so I'll take a look into it and see if I can provide a fix in the near future.

 

Thanks for the feedback!

 

Lee

Link to comment
Share on other sites

Following these bug reports, I decided to heavily update the program.

 

For this version I have completely rewritten the program to update the layout and code formatting, and furthermore added the ability to write the output data to a Text or CSV file of the user's choice.

 

This version is a 'Beta' version however, since I have changed the method to create a Table Block Preview and I don't have a 64-bit system on which the test the code, so there might well be some error's for users running 64-bit machines.

 

If you are using a 64-bit environment, if possible I would kindly ask if you could test the Beta program (as linked in the first post), and, if the program works, please let me know the ACAD Version you are using; or, if the program errors, please post the error message (and the Line# of the error if possible), and again, which ACAD Version you are using.

 

I hope the program can benefit your workflow.

 

Kind Regards,

 

Lee

Link to comment
Share on other sites

Lee,

 

Have just done quick test.

It does seem to label and count all the blocks correctly and list them in the autocad text window, but when I output to a table with preview to create legend I get a blank table with the following error.

Specify Point for Table: ; error: Exception occurred: 0xC0000005 (Access

Violation)

; warning: unwind skipped on exception

; error: Exception occurred: 0xC0000005 (Access Violation)

 

AutoCAD 2011

Win 7

64 Bit

 

Hope this helps your development.

Link to comment
Share on other sites

I tested beta version on win 7 64bit, autocad 2011 64bit.

Export to csv works good,

export to table without block preview works good,

export to table with block preview ends with bugs:

Command: COUNT

Select Blocks to Count <All> :

Block Name.............................................Count
------------------------------------------------------------
CPEL_2814..................................................1
el - glosnik...............................................1
el - sap centrala pozarowa.................................1
el - sap czujka dymu.......................................4
el - sap czujka dymu 520...................................1
el - sap czujka dymu miedzystropowa........................5
el - sap czujka dymu miedzystropowa 2......................1
el - sap czujka dymu miedzystropowa 3......................1
el - sap czujka dymu miedzystropowa 4......................1
el - sap przelacznik wentylacji............................1
el - sap rop...............................................2
el - sap rop 2.............................................1
el - sap rpo...............................................2
el - sap sygnalizator akustyczny...........................1
el - sap sygnalizator optyczny.............................1
------------------------------------------------------------

Output [Table/File/Settings] <Exit>: s

Output [Table/File/Settings] <Exit>: t

Specify Point for Table: ; error: Exception occurred: 0xC0000005 (Access 
Violation)
; warning: unwind skipped on exception
; error: Exception occurred: 0xC0000005 (Access Violation)

Link to comment
Share on other sites

Tested on Win 7 64 bit autocad2010

 

Export to file works with and without Block Preview / tableTitle activated.

 

While "table" works with "Block Preview" not activated.

 

"table" with "Block Preview" activated I get empty table with this message

 

ximpianti elettrico.......................................29

zf_108.....................................................1

zf_216.....................................................2

------------------------------------------------------------

Output [Table/File/Settings] : s

Output [Table/File/Settings] : t

Specify Point for Table: ; error: Exception occurred: 0xC0000005 (Access

Violation)

; warning: unwind skipped on exception

; error: Exception occurred: 0xC0000005 (Access Violation)

Command:

Link to comment
Share on other sites

Thanks for the report Sadhu, appreciated.

 

Its the method to implement the Block Preview on 64-bit systems that is causing the problems - everything is working fine on my 32-bit system.

 

I'm still working on it and will hopefully have it sorted soon.

 

Lee

Link to comment
Share on other sites

Please try the updated code (Version 1.3) :)

 

My thanks go to Jeff_M at theSwamp for helping me hopefully fix the issues with the Block Preview.

 

Lee

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...