Jump to content

a lisp to apply 3 different lisp to 3 obj types filtered from one selection


gilsoto13

Recommended Posts

Hi Everyone:

 

I think I can surprise many people with this final task I am willing to develop somehow...

 

I want to Make a lisp to allow me to select an entire detail or plan view... then this lisp must split the selection for 3 different object type groups: Dimensions & leaders, text (and if possible mtext), and blocks...

 

And then the lisp will aply 1 command or lisp to each one of those 3 selection groups...

This is to standarize a Detail or plan according to our standard text, dimension and block sizes... I will try to take care of this part...

 

But I dont know how to split the selection into 3 selection sets...

Any help will be appreciated..

Link to comment
Share on other sites

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    13

  • gilsoto13

    13

  • mark_acadd

    2

  • JohnM

    1

Hi Everyone:

 

I think I can surprise many people with this final task I am willing to develop somehow...

 

I want to Make a lisp to allow me to select an entire detail or plan view... then this lisp must split the selection for 3 different object type groups: Dimensions & leaders, text (and if possible mtext), and blocks...

 

And then the lisp will aply 1 command or lisp to each one of those 3 selection groups...

This is to standarize a Detail or plan according to our standard text, dimension and block sizes... I will try to take care of this part...

 

But I dont know how to split the selection into 3 selection sets...

Any help will be appreciated..

 

Once you've made the selection, just iterate through them applying procedure A, B or C based on object type. (assoc 0 or (vla-get-objectname using cond.

Link to comment
Share on other sites

Once you've made the selection, just iterate through them applying procedure A, B or C based on object type. (assoc 0 or (vla-get-objectname using cond.

 

Ok, I found this made by you... I am gonna start from here..

 
;text & leader delete
;only selects text, mtext & leaders to erase
;created: alan thompson - 4.17.08
(defun c:TX (/ ss)
 (prompt "\nSelect text & leaders to erase: ")
 (setq ss (ssget '((0 . "TEXT,MTEXT,LEADER"))))
(if ss
 (progn
   (command "erase" ss "" )
   (princ (strcat "\n " (rtos (sslength ss)) " Text and/or Leader objects have been deleted."))
 );progn
 (princ "\nNo text selected, try again.")
);if
 (princ)
)

 

Then, How can I add 3 different selection groups with a specified assigned abbreviation, and run a specified command or function to each selection group at once?... I tried to just write something but I guess I gotta keep reading..

 

 
;Detail updater to current scale
;tried to be written: Paulo Gil .. today
(defun c:UD (/ ss ss2 ss3)
 (prompt "\nSelect a whole detail to update: ")
 (setq ss (ssget '((0 . "TEXT,MTEXT"))))
 (setq ss2 (ssget '((0 . "INSERT"))))
 (setq ss3 (ssget '((0 . "DIMENSION,LEADER"))))
(if ss
 (progn
   (command "_.chprop" ss "color" "blue" "")
 );progn
 (princ "\nNothing selected, try again.")
);if
(if ss2
 (progn
   (command "_.chprop" ss2 "layer" "Patt" "")
 );progn
 (princ "\nNothing selected, try again.")
);if
(if ss3
 (progn
   (command "_.chprop" ss3 "layer" "Dims" "")
 );progn
 (princ "\nNothing selected, try again.")
);if
 (princ)
)

Link to comment
Share on other sites

Just make one large selection set, then iterate through the list using cond and if it "MTEXT" matches (cdr (assoc 0 (entget e)))), then change the color.

 

BTW, I obviously don't mind you using my code, but please remove my name from anything that I did not write.

 

;Detail updater to current scale
[color=Red];created: alan thompson - 4.17.08[/color]
(defun c:UD (/ ss ss2 ss3)

Link to comment
Share on other sites

Give this a try, untested and in vla, because I'm lazy...

(defun c:UD (/ #SS)
 (vl-load-com)
 (cond
   ((setq #SS (ssget ":L" '((0 . "MTEXT,TEXT,INSERT,DIMENSION,LEADER"))))
    (vlax-for x (setq
                  #SS (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
                ) ;_ setq
      (cond
        ;; text, mtext
        ((vl-position (vla-get-objectname x) (list "AcDbMText" "AcDbText")) (vla-put-color x 5))
        ;; blocks
        ((eq (vla-get-objectname x) "AcDbBlockReference")
         (vl-catch-all-apply 'vla-put-layer (list x "Patt"))
        )
        ;; dimension, leader
        ((wcmatch (vla-get-objectname x) "*Leader*,*Dimension*")
         (vl-catch-all-apply 'vla-put-layer (list x "Dims"))
        )
      ) ;_ cond
    ) ;_ vlax-for
    (vl-catch-all-apply 'vla-delete (list #SS))
   )
 ) ;_ cond
) ;_ defun

Link to comment
Share on other sites

Do you think it would be easer to window the objects the list the windows corner points

The jus pass it to the 3 ssget functions?

 

Why go though all that trouble, when you can just iterate through it and change objects based on object type.

Link to comment
Share on other sites

I haven´t checked it out either... but I guess this is what I wanted, the correct order for three different selection sets and only one lisp... Now I guess I can use the

(vl-cmdf "_.any command")

on these "lists"

 

I actually want to use this new lisp for 2 different purposes... one is for a "Detail scale updater"... and the other will be the "mask all"

 

So, in the "Detail Scale updater" when you select a bunch of objects the lisp will apply

 

1 lisp function to filtered blocks...

1 lisp function to Text, Mtext

1 command (Dim--Update) to Dimensions and leaders

 

The "mask all" will apply

1 Command to Dtext (textmask)

1 lisp function to Mtext (yours, jejeje)

1 lisp or vlx to Dimensions

 

This is what I am trying to do... but there's no hurry for this... i'll try to go step by step.

 

I am still working hard everyday to finish the blocks collection.. I finished extracting all collections... The next step is just merging all the blocks into their respective dwgs for compilation.

 

I am using a Batch dxf to dwg successfully, and I will try a batch PDF to DWG today afternoon for some construction details that were available only in pdf format.

 

 

 

 

 

(vl-catch-all-apply 'vla-put-layer (list x "Patt"))

Give this a try, untested and in vla, because I'm lazy...

(defun c:UD (/ #SS)
 (vl-load-com)
 (cond
   ((setq #SS (ssget ":L" '((0 . "MTEXT,TEXT,INSERT,DIMENSION,LEADER"))))
    (vlax-for x (setq
                  #SS (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
                ) ;_ setq
      (cond
        ;; text, mtext
        ((vl-position (vla-get-objectname x) (list "AcDbMText" "AcDbText")) (vla-put-color x 5))
        ;; blocks
        ((eq (vla-get-objectname x) "AcDbBlockReference")
         (vl-catch-all-apply 'vla-put-layer (list x "Patt"))
        )
        ;; dimension, leader
        ((wcmatch (vla-get-objectname x) "*Leader*,*Dimension*")
         (vl-catch-all-apply 'vla-put-layer (list x "Dims"))
        )
      ) ;_ cond
    ) ;_ vlax-for
    (vl-catch-all-apply 'vla-delete (list #SS))
   )
 ) ;_ cond
) ;_ defun

Link to comment
Share on other sites

nice one!.but how can i apply those lisp in my autocad!..i dont know how to put it.i mean the codes..where can i put it!..help me guys..im just a newbies in field of autocad and i hope i can learn a lot from!..thanks and god bless!

Link to comment
Share on other sites

nice one!.but how can i apply those lisp in my autocad!..i dont know how to put it.i mean the codes..where can i put it!..help me guys..im just a newbies in field of autocad and i hope i can learn a lot from!..thanks and god bless!

Well, without any additional information, just change object types, layer names, colors, etc. to what you want.

 

Give some parameters and we can make something work. :)

Link to comment
Share on other sites

Well, without any additional information, just change object types,

layer names, colors, etc. to what you want.

 

Give some parameters and we can make something work.

 

Well, at this time it's all pretty good...But If you want some extra-work, I was wondering

if I could find a small lisp routine or some code to automatically change selected text and

mtext to current style and height without prompt... that' the only thing left to complete

the first lisp...

 

(defun c:UD (/ #SS)
 (vl-load-com)
 (cond
   ((setq #SS (ssget ":L" '((0 . "MTEXT,TEXT,INSERT,DIMENSION,LEADER"))))
    (vlax-for x (setq
                  #SS (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
                ) ;_ setq
      (cond
        ;; text, mtext
        ((vl-position (vla-get-objectname x) (list "AcDbMText" "AcDbText"))
         (vla-put-color x 5)
[color=red]         (vla-put-height x (getvar 'textsize))[/color]
[color=red]         (vla-put-stylename x (getvar 'textstyle))[/color]
        )
        ;; blocks
        ((eq (vla-get-objectname x) "AcDbBlockReference")
         (vl-catch-all-apply 'vla-put-layer (list x "Patt"))
        )
------------------------------------
;Here is the place to apply a function (another lisp) that Lee Mac wrote for me.. the "Bu.lsp" But it shouldn't be
;applied to all selected blocks, only those we use as standard, so, these blocks must be re-filtered to grab only 
;those in a list, and then apply the bu.lsp to that last selection of blocks.
;Bu.lsp Update selected blocks to current Dimscale, supports Normal, attributed and dynamic blocks
;by Lee Mac from Cadtutor, Sep. 2009
(defun c:bu (/ *error* doc oldc ss sel scl)
 (vl-load-com)
  (defun *error* (msg)
   (if doc (vla-EndUndoMark doc))
   (if oldc (setvar "CMDECHO" oldc))
   (if (not
         (wcmatch
           (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
     (princ (strcat "\n** Error: " msg " **")))
   (princ))

 (setq doc (vla-get-ActiveDocument
             (vlax-get-acad-object)))
 (setq oldc (getvar "CMDECHO") scl (getvar "DIMSCALE"))
 (setvar "CMDECHO" 0)
 (prompt "\nSelect Blocks to match current dimscale... ")
 (if (setq ss (ssget '((0 . "INSERT"))))
   (progn
     (vla-StartUndoMark doc)
     (command "_.-objectscale" ss "" "_add" "1:1" "")
     (setvar "CANNOSCALE" "1:1")
     (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet doc))        
       (foreach x
         (if (eq :vlax-true
               (vla-get-IsDynamicBlock Obj))
           '(XEffectiveScaleFactor YEffectiveScaleFactor ZEffectiveScaleFactor)
           '(XScaleFactor YScaleFactor ZScaleFactor))
         (vlax-put-property Obj x scl))
       (if (eq :vlax-true (vla-get-HasAttributes Obj))
         (command "_.attsync" "_Name"
           (vlax-get-property Obj
             (if (eq :vlax-true
                   (vla-get-isDynamicBlock Obj)) 'EffectiveName 'Name)))))
     (vla-delete sel)
     (vla-EndUndoMark doc)))

 (setvar "CMDECHO" oldc)
 (princ))


        ;; dimension, leader
        ((wcmatch (vla-get-objectname x) "*Leader*,*Dimension*")
         (vl-catch-all-apply 'vla-put-layer (list x "Dims"))
        )
      ) ;_ cond
    ) ;_ vlax-for
    (vl-catch-all-apply 'vla-delete (list #SS))
   )
 ) ;_ cond
) ;_ defun
-------------------------------
;; dimension, leader
((wcmatch (vla-get-objectname x) "*Leader*,*Dimension*")
(vl-catch-all-apply 'vla-put-layer (list x "Dims"))
----------------------------------------------------
;Here is the place to apply the command Dimupdate to filtered dimensions and leaders
-----------------------

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

Bu.lsp

textup.lsp

Link to comment
Share on other sites

Well, at this time it's all pretty good...But If you want some extra-work, I was wondering

if I could find a small lisp routine or some code to automatically change selected text and

mtext to current style and height without prompt... that' the only thing left to complete

the first lisp...

Here, I was bored....

(defun c:TextUp (/ #SS)
 (cond
   ((setq #SS (ssget "_:L" '((0 . "MTEXT,TEXT"))))
    (vlax-for x (setq
                  #SS (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
                ) ;_ setq
      (vla-put-height x (getvar 'textsize))
      (vla-put-stylename x (getvar 'textstyle))
    ) ;_ vlax-for
    (vl-catch-all-apply 'vla-delete (list #SS))
   )
 ) ;_ cond
 (princ)
) ;_ defun

Link to comment
Share on other sites

Here, I was bored....

(defun c:TextUp (/ #SS)
 (cond
   ((setq #SS (ssget "_:L" '((0 . "MTEXT,TEXT"))))
    (vlax-for x (setq
                  #SS (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
                ) ;_ setq
      (vla-put-height x (getvar 'textsize))
      (vla-put-stylename x (getvar 'textstyle))
    ) ;_ vlax-for
    (vl-catch-all-apply 'vla-delete (list #SS))
   )
 ) ;_ cond
 (princ)
) ;_ defun

 

Incredibol... It works... I guess I just left to do the standard blocks list... which is a very long list... maybe near a thousand block names... But if you have a chance... I uploaded the lisp files to apply to filtered blocks, text and mtext,

 

It will be for us like using Revit but in Autocad, this way we can change everything involved in a detail scale automatically in one step. A big big accomplishment.

 

But is it possible to apply those 2 lisp to filtered selections as you did here?

http://www.cadtutor.net/forum/showthread.php?t=37475&page=2

Link to comment
Share on other sites

Incredibol... It works... I guess I just left to do the standard blocks list... which is a very long list... maybe near a thousand block names... But if you have a chance... I uploaded the lisp files to apply to filtered blocks, text and mtext,

 

It will be for us like using Revit but in Autocad, this way we can change everything involved in a detail scale automatically in one step. A big big accomplishment.

 

But is it possible to apply those 2 lisp to filtered selections as you did here?

http://www.cadtutor.net/forum/showthread.php?t=37475&page=2

 

You could :?, but it would be better suited to just combine the two or turn them into subs.

Link to comment
Share on other sites

Is this what you are wanting?

(defun c:UD2 (/ #SS)
 (vl-load-com)
 (cond
   ((setq #SS (ssget ":L" '((0 . "MTEXT,TEXT,INSERT,DIMENSION,LEADER"))))
    (vlax-for x (setq
                  #SS (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
                ) ;_ setq
      (cond
        ;; text, mtext
        ((vl-position (vla-get-objectname x) (list "AcDbMText" "AcDbText"))
         (vla-put-color x 5)
[color=Red]          (vla-put-height x (getvar 'textsize))
         (vla-put-stylename x (getvar 'textstyle))[/color]
        )
        ;; blocks
        ((eq (vla-get-objectname x) "AcDbBlockReference")
         (vl-catch-all-apply 'vla-put-layer (list x "Patt"))
        )
        ;; dimension, leader
        ((wcmatch (vla-get-objectname x) "*Leader*,*Dimension*")
         (vl-catch-all-apply 'vla-put-layer (list x "Dims"))
        )
      ) ;_ cond
    ) ;_ vlax-for
    (vl-catch-all-apply 'vla-delete (list #SS))
   )
 ) ;_ cond
) ;_ defun

Link to comment
Share on other sites

That's exactly what I wanted... but without

         (vla-put-color x 5)

This was just to start...

 

How would you Update dims and leaders to current settings as using dimupdate command, but with vla?

 

How would you make this lisp a subfunction?... I guess first you change the

(defun c:bu (/ *error* doc oldc ss sel scl)

for something like this:

(defun AT:bu (/ *error* doc oldc ss sel scl)

and then when you get your blocks, you go like:

    (vlax-for x (setq #SS (vla-get-activeselectionset *AcadDoc*))
      (AT:Bu (vla-get-insertionpoint x)
                (if (vlax-property-available-p x 'EffectiveName)
                  (vla-get-effectivename x)
                  (vla-get-name x)
                ) ;_ if

 

And then, I don't know...

 

I actually don´t know anything... I just find the things...

 

You could :?, but it would be better suited to just combine the two or turn them into subs.
Link to comment
Share on other sites

That's exactly what I wanted... but without

         (vla-put-color x 5)

This was just to start...

 

How would you Update dims and leaders to current settings as using dimupdate command, but with vla?

 

How would you make this lisp a subfunction?... I guess first you change the

(defun c:bu (/ *error* doc oldc ss sel scl)

for something like this:

(defun AT:bu (/ *error* doc oldc ss sel scl)

and then when you get your blocks, you go like:

    (vlax-for x (setq #SS (vla-get-activeselectionset *AcadDoc*))
      (AT:Bu (vla-get-insertionpoint x)
                (if (vlax-property-available-p x 'EffectiveName)
                  (vla-get-effectivename x)
                  (vla-get-name x)
                ) ;_ if

And then, I don't know...

 

I actually don´t know anything... I just find the things...

 

Not sure about dimup, never had a reason to try it, if i have some time, I'll look. As far as converting a routine to a sub, from the simplest change, just remove the c: You don't have to add AT:, that's just what I add to my (Alan Thompson) subroutines. What you have posted will not work...what's c:BU?

Link to comment
Share on other sites

Not sure about dimup, never had a reason to try it, if i have some time, I'll look. As far as converting a routine to a sub, from the simplest change, just remove the c: You don't have to add AT:, that's just what I add to my (Alan Thompson) subroutines. What you have posted will not work...what's c:BU?

 

So, I guess I kind of understand how to make a subroutine... but still can´t do it by myself... I am not in a hurry with this.... so I will wait for heaven to light you on again, hopefully you'll find some more time later and we can keep this post going on...

 

Steps left to finish:

 

- Changing Bu.lsp to subrutine to apply to filtered blocks..

- Finding the way to apply current dim settings to filtered dims and leaders from selection...

 

-Get all in shape to work together without prompt.

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...