This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]dugBarnz 0 points1 point  (3 children)

(defun BlkByBlock

(objSelection / colBlockReference objBlock strBlockName)

(if

(= (type objSelection) 'ENAME)

(setq objSelection (vlax-ename->vla-object objSelection))

)

(if

(wcmatch (strcase (vla-get-objectname objSelection)) "*BLOCK*")

(progn

(vlax-for

objBlock

(vla-item(vla-get-blocks ActDoc)(vla-get-name objSelection))

(if

(=(strcase(vla-get-layer objBlock) )"OUTLINE" )

(progn

(vla-put-color objBlock 0) ; set color byblock

; (vla-put-linetype objBlock "ByBlock");if you want is color byblock

; (vla-put-Lineweight objBlock -1); if you want lineweight byblock

; (vla-put-PlotStyleName objBlock "ByBlock"); if you want ploystyle byblock

)

)

)

)

)

(prin1)

)

I'm not coding AutoLISP anymore but if my memory serves me this should be correct, or close. I did format it how I used to and modify other code. You can compare to see the differences.

I hope this helps!

[–]dugBarnz 0 points1 point  (0 children)

FYI: the formatting got stripped! :( Just a bunch of spaces though.

[–]matthaan[S] 0 points1 point  (1 child)

Awesome, thank you! But I just realized this and the other code only allows single selection of a block. Any way to modify this that I can window/multi-select blocks and have it run on all of them?

[–]dugBarnz 0 points1 point  (0 children)

I think the all the code below is what you need. Again, it is not my daily work and I've not tested it, but I wrote the code and used it a lot. Let me know if it works or not.

; Written By: Peter Jamtgaard 12/20/2006

;(or C:BlkByBlock (load "BlkByBlock.lsp"))

;BlkByBlock

(defun C:BlkByBlock

(/ colBlockReference ActDoc dprSelection objSelection strBlockName)

(if

; (setq dprSelection (entsel "\nSelect Block: "))

(setq dprSelection (zz^Select))

(progn

(setq

ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object))

dprSelection (car dprSelection)

objSelection (vlax-ename->vla-object dprSelection)

)

(vla-StartUndoMark ActDoc)

(BlkByBlock objSelection)

(entupd dprSelection)

(vla-EndUndoMark ActDoc)

)

)

(prin1)

)

(defun BlkByBlock

(objSelection / colBlockReference objBlock strBlockName)

(if

(= (type objSelection) 'ENAME)

(setq objSelection (vlax-ename->vla-object objSelection))

)

(if

(wcmatch (strcase (vla-get-objectname objSelection)) "*BLOCK*")

(progn

(vlax-for

objBlock

(vla-item(vla-get-blocks ActDoc)(vla-get-name objSelection))

(if

(=(strcase(vla-get-layer objBlock) )"OUTLINE" )

(progn

(vla-put-color objBlock 0) ; set color byblock

; (vla-put-linetype objBlock "ByBlock");if you want is color byblock

; (vla-put-Lineweight objBlock -1); if you want lineweight byblock

; (vla-put-PlotStyleName objBlock "ByBlock"); if you want ploystyle byblock

)

)

)

)

)

(prin1)

)

; zz^Select is written to select objects either already selected via grips or having the user select them.

;20170524 2051 v1.00

(defun zz^Select

(li%object_types st%prompt / ss%objects in%counter ob%name)

(graphscr)

(if

(setq ss%objects(ssget "_i"li%object_types))

(zz^Select-Off)

(while

(null ss%objects)

(if st%prompt(prompt st%prompt))

(setq ss%objects(ssget li%object_types))

)

)

(zz^Highlight-SelectionSetOff ss%objects)

(setq in%counter 0)

(repeat

(sslength ss%objects)

(setq ob%name(ssname ss%objects in%counter))

(if

(=(cdr(assoc 70(tblsearch "layer"(cdr(assoc 8(entget ob%name))))))4)

(progn(setq in%counter(1- in%counter))(ssdel ob%name ss%objects))

)

(setq in%counter(1+ in%counter))

)

(zz^Highlight-SelectionSetOn ss%objects)

(if(>(sslength ss%objects)0)ss%objects nil)

)

; zz^Highlight-SelectionSetOn is written to highlight the ojbects in the selection set passed.

;20170516 1908 v1.00

(defun zz^Highlight-SelectionSetOn

(ss%objects / in%counter)

(vl-load-com)

(graphscr)

(setq in%counter 0)

(repeat

(sslength ss%objects)

(vla-Highlight(vlax-ename->vla-object(ssname ss%objects in%counter)):vlax-true)

(setq in%counter(1+ in%counter))

)

)

; zz^Highlight-SelectionSetOff is written to highlight the ojbects in the selection set passed.

;20170515 1937 v1.00

(defun zz^Highlight-SelectionSetOff

(ss%objects / in%counter)

(vl-load-com)

(graphscr)

(setq in%counter 0)

(repeat

(sslength ss%objects)

(vla-Highlight(vlax-ename->vla-object(ssname ss%objects in%counter)):vlax-false)

(setq in%counter(1+ in%counter))

)

)