Jump to content

Recommended Posts

Posted (edited)

I have several dynamic blocks with text in them, what I am trying to do is set up a LISP where I can select them all and it will adjust the visibilities to turn the text on. Some of the blocks have multiple options, so there needs to be something for what the current visibility is to the new one. For example, "Electric - No Stationing" would go to the "Electric" visibility.

 

The code I have, though not working properly is. The issue is in determining the current visibility since without that part in the code, it works fine, other than it turns all of the blocks to the visibility in they syntax.

 

(defun c:staon (/ BlockName BlkName BlkVis)
 (setvar "cmdecho" 0)
 (vl-load-com)
 ;Syntax       Begin Visibility      End Visibility
   (ChangeBlk    "Electric - No Stationing"    "Electric")
 (princ))


(defun ChangeBlk (BlkBegVis BlkVis / )
 (setq BlockName (mapcar (function strcase)
                         '("manhole-sta")))
      
     (if (setq ss (ssget ":L"
                     (list '(0 . "INSERT")
                           (cons 2
                                 (apply (function strcat)
                                        (cons "`*U*,"
                                              (mapcar (function (lambda (s) (strcat s ",")))
                                                      BlockName)))))))
   (progn
     (vlax-for x (setq ss (vla-get-activeselectionset
                            (cond (*AcadDoc*)
                                  ((setq *AcadDoc* (vla-get-activedocument
                                                     (vlax-get-acad-object)))))))
       (if (and (vl-position
                  (strcase (vlax-get-property
                             x
                             (if (vlax-property-available-p x 'EffectiveName)
                               'EffectiveName
                               'Name)))
                  BlockName)
                (eq (vla-get-isDynamicBlock x) :vlax-true))                   
         (vl-some (function (lambda (z)
                  (if (eq (vlax-get-property z "Value") "Visibility")
                (if (= z BlkBegVis)
                  (setq z BlkBegVis)))))
          
              (function (lambda (p)
                              (if (eq (vlax-get-property p "PropertyName") "Visibility")
                                (not (vl-catch-all-error-p
                                       (vl-catch-all-apply
                                         (function vlax-put-property)
               (foreach z
                                         (list p "Value" BlkVis))))))))
                  (vlax-invoke x 'GetDynamicBlockProperties))))
     (vla-delete ss)))
 )

manhole-sta.dwg

Edited by Ohnoto
Posted

Look into the DynamicBlockReferenceProperty Object in the VLIDE Developer Documentation. :wink:

Posted
(defun ChangeBlk (BlkBegVis BlkVis / )
 (setq BlockName (mapcar (function strcase)
                         '("manhole-sta")))

     (if (setq ss (ssget ":L"
                     (list '(0 . "INSERT")
                           (cons 2
                                 (apply (function strcat)
                                        (cons "`*U*,"
                                              (mapcar (function (lambda (s) (strcat s ",")))
                                                      BlockName)))))))
   (progn
     (vlax-for x (setq ss (vla-get-activeselectionset
                            (cond (*AcadDoc*)
                                  ((setq *AcadDoc* (vla-get-activedocument
                                                     (vlax-get-acad-object)))))))
       (if (and (vl-position
                  (strcase (vlax-get-property
                             x
                             (if (vlax-property-available-p x 'EffectiveName)
                               'EffectiveName
                               'Name)))
                  BlockName)
                (eq (vla-get-isDynamicBlock x) :vlax-true))
         [color=blue] (mapcar[/color]
[color=blue]                   (function[/color]
[color=blue]                     (lambda (z[/color][color=blue])[/color]
[color=blue]                     (if[/color]
[color=blue]                       (and[/color]
[color=blue]                         (eq (vlax-get-property z "PropertyName")[/color]
[color=blue]                             "Visibility")[/color]
[color=blue]                         (eq (variant-value[/color]
[color=blue]                               (vlax-get-property z "Value"))[/color]
[color=blue]                             BlkBegVis)[/color]
[color=blue]                         (member[/color]
[color=blue]                           BlkVis[/color]
[color=blue]                           (vlax-get z 'AllowedValues)))[/color]
[color=blue]                        (vla-put-value z BlkVis))))[/color]
[color=blue]                 (vlax-invoke x 'GetDynamicBlockProperties[/color][color=blue]))[/color])
       )
     (vla-delete ss)))
 )

Posted (edited)

Not that you have to, but I think you can shorten this up a bit... Consider this example:

 

(defun CHANGEBLOCK  (visState cVisState / ss dynProps)
 [color=green];; Example: ([/color][color=green]changeblock [i]<visibilityState>[/i])[/color]
 (vl-load-com)
 (if (setq ss (ssget "_x" (list '(0 . "INSERT") (cons 410 (getvar 'ctab)))))
   (progn
     (vla-startundomark
       (cond
         (*activeDoc*)
         ((setq *activeDoc*
                 (vla-get-activedocument (vlax-get-acad-object))))))
     (vlax-for x (setq ss (vla-get-activeselectionset *activeDoc*))
       (if (and (= :vlax-true (vla-get-isdynamicblock x))
                (vl-position
                  (strcase (vla-get-effectivename x))
                  '("MANHOLE-STA"
                    [color=green];; <- Add additional block names here[/color]
                    ))
                (vl-position
                  visState
                  (vlax-get (setq dynProps
                                   (car (vlax-invoke
                                          x
                                          'getdynamicblockproperties)))
                            'allowedvalues))
                (= cVisState (strcase (vlax-get x 'value))))
          (progn
            (vlax-put-property dynProps 'value visState))))
     (vla-delete ss)
     (vla-endundomark *activeDoc*)))
 (princ))

 

** Notes -

 

Be mindful of how you call an object's properties as this will help you reduce the amount of code necessary to get the desired output; for example, consider the different output yielded by this:

 

(vla-get-allowedvalues <dynPropsObj>)

 

... as compared to this:

 

(vlax-get <dynPropsObj> allowedvalues)

 

Also, be careful when naming global variables, for example in your code you used:

 

...
   (cond ([color=red][color=black]*[/color]Acad[color=blue]Doc[/color][/color][color=black]*[/color])
     ((setq [color=red][color=black]*[/color]Acad[color=blue]Doc[/color][/color][color=black]*[/color] (vla-get-[color=black]active[color=blue]doc[/color]ument[/color] (vlax-get-[color=red]acad[/color]-object)))))))
...

 

... This may be confusing to some; consider using *acDoc*, or *activeDoc* instead.

Edited by BlackBox
Quote corrected
Posted

The way a code is written is like a signature to the author.

so as much as possible i wouldnt want to deviate from the OP's original code thats why i left it as it is. highlighted portions are the changes i made.

 

Thank you for the snippets Renderman (very helpful)

 

BTW: can you tell me what are pros and cons between

foreach

mapcar

vl-some

 

Cool beans

Posted

Thanks for help guys.

 

@pBe... I actually can't tell you the pros and cons of each of those.

 

I'm still learning LISP, been learning it for only about 2 months now. Our last LISP writer left a couple months ago and I decided to pick up learning it. When he left, he deleted much of the current code we had and we were only able to get coding going back to last year. (Long story that would make for a good drama novel). Since then I have studied the code we have and while I do have a book it doesn't go much into the VL functions that seem to be more widely used here.

 

While I have been able to create several programs here, there are still things I just don't know and LISP isn't exactly taught a lot, because I would be interested in taking classes for it if I could find one.

 

I've done foreach in the past for things on every page where I get the length of the layoutlist and want something applied on each page. mapcar and vl-some are things that were put into a piece of code that Alanjt assisted me on with one of my first programs. I've reused mapcar for listing out specific blocks to be used in a LISP. I apologize if the coding looked weird, I was using what I have learned so far with my various programs.

Posted

Maybe these will help?

http://lee-mac.com/dynamicblockfunctions.html

Posted

Alright, there's a lot here, so please bear with me....

 

The way a code is written is like a signature to the author.

so as much as possible i wouldnt want to deviate from the OP's original code thats why i left it as it is. highlighted portions are the changes i made.

 

Call me lazy, I simply quoted you as you made the latest post... aside from the quote tagging you, my statements were general, non-author specific. I've corrected the quote tag.

 

Thank you for the snippets Renderman (very helpful)

 

You're welcome (glad to hear it) :)

 

BTW: can you tell me what are pros and cons between

foreach

mapcar

vl-some

 

In summary... the biggest difference between foreach and mapcar is two-fold; the first being syntax, and the second being the returned values (See the developer documentation for more information).

 

... while I do have a book it doesn't go much into the VL functions that seem to be more widely used here.

 

There are many resources out there, but I just purchased David Stein's newest eBook "The Visual LISP Developer's Bible, 2011 Edition" for $7.99 (no tax). Before this book came out, I found his earlier book "..., 2003 Edition" to be invaluable prior to this release.

 

While I have been able to create several programs here, there are still things I just don't know and LISP isn't exactly taught a lot, because I would be interested in taking classes for it if I could find one.

 

If you're looking for *formal* (non-forum) training, you may have to peruse Autodesk University, or bite the bullet and take some Visual Studio courses to learn .NET. Everything I've learned for developing with AutoLISP / Visual LISP has come from reading, and the kind, patient, fantastic members at this, and other forums.

 

Maybe these will help?

http://lee-mac.com/dynamicblockfunctions.html

 

Lee, your site is really coming along nicely... you're hard work, and free code is greatly appreciated.

 

Edit - Whew! :sweat: Finally made it... if you're still with me, you deserve a cold one. Cheers! :beer:

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