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

Need help with ssget function for LISP routine

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
967 Views, 7 Replies

Need help with ssget function for LISP routine

Hi everyone,

I found this LISP routine by Peter Jamtgaard on an AUGI. It will take the entities in a block and change them to by "By Block". I find it very useful, but I can only use the command on one block at a time. I want to be able to use the commend on a selection set of blocks to speed things up. From what I have read, I need to change the 'entsel' function to ssget. I have tried a few times, but I dont know very much about writing LISPs and I have definitely doing something wrong with the syntax. Below is original LISP code by Peter Jamtgaard:

 ; Written By: Peter Jamtgaard 12/20/2006
;^P(or C:BlkByBlock (load "BlkByBlock.lsp"));BlkByBlock
(defun C:BlkByBlock (/ colBlockReference
                    ActDoc dprSelection
                    objSelection strBlockName
                 )
 (if (setq dprSelection (entsel "\nSelect Block: "))
  (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)
                      )

    (vla-put-color objBlock 0) ; set color byblock
;    (vla-put-linetype EOBJ "ByBlock") if all you want is color byblock
;    (vla-put-Lineweight EOBJ -1) if all you want is color byblock
;    (vla-put-PlotStyleName EOBJ "ByBlock") if all you want is color byblock
   )
  )
 )
 (prin1)
)
(prin1)
Tags (3)
7 REPLIES 7
Message 2 of 8
marko_ribar
in reply to: Anonymous

Here is quick mod... Untested, though...

 

(defun c:processblocks ( / *error* BlkByBlock ss i )

  (vl-load-com)

  (defun *error* ( m )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (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)
                        )

      (vla-put-color objBlock 0) ; set color byblock
  ;    (vla-put-linetype EOBJ "ByBlock") if all you want is color byblock
  ;    (vla-put-Lineweight EOBJ -1) if all you want is color byblock
  ;    (vla-put-PlotStyleName EOBJ "ByBlock") if all you want is color byblock
     )
    )
   )
   (prin1)
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
      (BlkByBlock (ssname ss (setq i (1- i))))
(entupd (ssname ss i)) ) )
(vla-regen *adoc* acactiveviewport) (*error* nil) )
Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 3 of 8
Anonymous
in reply to: marko_ribar

Doesn't seem to be working. When I try to use PROCESSBLOCKS, i get the following error:

bad argument type: VLA-OBJECT nil

 

 

Message 4 of 8
marko_ribar
in reply to: Anonymous

Try it this time, once again... Note that there are no checks for xrefs and dynamic blocks which you may wanted to be excluded from processing... But I suppose you distinguish those and may create correct selection...

 

(defun c:processblocks ( / *error* BlkByBlock *adoc* ss i )

  (vl-load-com)

  (defun *error* ( m )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (defun BlkByBlock ( objSelection )
    (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 *adoc*)
                             (vla-get-name objSelection)
                           )

        (vla-put-color objBlock 0) ; set color byblock
   ;    (vla-put-linetype EOBJ "ByBlock") if all you want is color byblock
   ;    (vla-put-Lineweight EOBJ -1) if all you want is color byblock
   ;    (vla-put-PlotStyleName EOBJ "ByBlock") if all you want is color byblock
        )
      )
    )
    (prin1)
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
      (BlkByBlock (ssname ss (setq i (1- i))))
      (entupd (ssname ss i))
    )
  )
  (vla-regen *adoc* acactiveviewport)
  (*error* nil)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 5 of 8
cadffm
in reply to: Anonymous

..because Marko forgot one thing from the old code in hurry,

but this code is so ugly. As "better then nothing' or as example for the main program part still okay,

 

 

you can edit Marko quick shot

from

(if (setq ss (ssget "_:L" '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
       (BlkByBlock (ssname ss (setq i (1- i))))
       (entupd (ssname ss i))
   )
)

to

(if (setq ss (ssget "_:L" '((0 . "INSERT"))))
     (progn
         (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
         (repeat (setq i (sslength ss))
             (BlkByBlock (ssname ss (setq i (1- i))))
             (entupd (ssname ss i))
         )
    )
)

 

If you selected 99 inserts of block "test" it will edit 99times the same block(test),

and if the Layer is locked.. "crash"

 

cu

Sebastian

EESignature

Message 6 of 8
Anonymous
in reply to: cadffm

Great, that worked!

 

I have another question now:

If I want this LISP to also modify the Lineweight and Linetype entities to also be "By Block", how would I do that? I see there are a couple of lines that are commented out, I deleted the comment ; to see if that would work but it didn't change anything. Do you know how to modify that? I'm not the best at reading LISP code...

Message 7 of 8
cadffm
in reply to: Anonymous

EDITED all - i read to fast your post, sorry.

 

If you know that a semicolon marks the rest of the line in Lisp as a comment,
then the answer is: Please read the code !

 

If not: A semicolon declares everything in the line below as a comment,
read your code once and then you'll see what to do.

Open and edit codes in the VisualLispIDE and you will see comments in other colors, command VLIDE

 

 

  ;    (vla-put-linetype EOBJ "ByBlock") if all you want is color byblock
   ;    (vla-put-Lineweight EOBJ -1) if all you want is color byblock

 

(vla-put-linetype objBlock "ByBlock") ; linetype
(vla-put-Lineweight objBlock -1) ; lineweight

The wrong(old) variable name was the first problem.

Sebastian

EESignature

Message 8 of 8
marko_ribar
in reply to: Anonymous

My latest revision :
  1. (defun c:processblocks ( / *error* BlkByBlock *adoc* ss i lst )
  2. (vl-load-com)
  3. (defun *error* ( m )
  4. (vla-endundomark *adoc*)
  5. (if m
  6. (prompt m)
  7. )
  8. (princ)
  9. )
  10. (defun BlkByBlock ( objSelection / blkcoll )
  11. (if (= (type objSelection) 'ENAME)
  12. (setq objSelection (vlax-ename->vla-object objSelection))
  13. )
  14. (if (wcmatch (strcase (vla-get-objectname objSelection)) "*BLOCK*")
  15. (if (and
  16. (setq blkcoll (vla-item (vla-get-blocks *adoc*) (vla-get-name objSelection)))
  17. ;;;(= (vla-get-isdynamicblock blkcoll) :vlax-false) ;;; - if you need to process dynamic blocks as well - if you don't remove comments
  18. (= (vla-get-isxref blkcoll) :vlax-false)
  19. (not (vl-position (vla-get-name objSelection) lst))
  20. )
  21. (progn
  22. (setq lst (cons (vla-get-name objSelection) lst))
  23. (vlax-for objBlock blkcoll
  24. (vla-put-color objBlock 0)
  25. (vla-put-linetype objBlock "ByBlock")
  26. (vla-put-Lineweight objBlock -1)
  27. ;;;(vla-put-PlotStyleName objBlock "ByBlock") ;;; - if PlotStyle "ByBlock" don't exist - if exist remove comments
  28. )
  29. )
  30. )
  31. )
  32. )
  33. (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  34. (if (= 8 (logand 8 (getvar 'undoctl)))
  35. (vla-endundomark *adoc*)
  36. )
  37. (vla-startundomark *adoc*)
  38. (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
  39. (repeat (setq i (sslength ss))
  40. (BlkByBlock (ssname ss (setq i (1- i))))
  41. (entupd (ssname ss i))
  42. )
  43. )
  44. (vla-regen *adoc* acactiveviewport)
  45. (*error* nil)
  46. )
Marko Ribar, d.i.a. (graduated engineer of architecture)

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report