Jump to content
TheyCallMeJohn

Flip Parameter, Dynamic Blocks & Autolisp

Recommended Posts

TheyCallMeJohn

Does anyone know a clean way to toggle a specified flip parameter using auto lisp visual lisp?

 

I use the getdynprops, getdynpropvalue, putdynpropvalue [by Jeff Mishler based on code from Steve Doman, Herman Mayfarth and Tony Tanzillo] for most of my dynamic block changing needs but I can't get it they don't seem to work for the flip parameter.

Share this post


Link to post
Share on other sites
Lee Mac

Consider the following function:

[color=GREEN];; Toggle Flip State  -  Lee Mac[/color]
([color=BLUE]defun[/color] toggleflipstate ( obj )
   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]=[/color] [color=MAROON]"AcDbBlockReference"[/color] ([color=BLUE]vla-get-objectname[/color] obj))
           ([color=BLUE]=[/color] [color=BLUE]:vlax-true[/color] ([color=BLUE]vla-get-isdynamicblock[/color] obj))
       )
       ([color=BLUE]vl-some[/color]
           ([color=BLUE]function[/color]
               ([color=BLUE]lambda[/color] ( p )
                   ([color=BLUE]if[/color] ([color=BLUE]equal[/color] '(0 1) ([color=BLUE]vlax-get[/color] p 'allowedvalues)) [color=GREEN];; likely to be a flip parameter[/color]
                       ([color=BLUE]vla-put-value[/color] p ([color=BLUE]vlax-make-variant[/color] ([color=BLUE]-[/color] 1 ([color=BLUE]vlax-get[/color] p 'value)) [color=BLUE]vlax-vbinteger[/color]))
                   )
               )
           )
           ([color=BLUE]vlax-invoke[/color] obj 'getdynamicblockproperties)
       )
   )
)

Usage:

(toggleflipstate [color=green]<VLA-Dynamic-Block-Reference-Object>[/color])

Example program:

([color=blue]defun[/color] c:flip ( [color=blue]/[/color] obj )
   ([color=blue]if[/color] ([color=blue]setq[/color] obj ([color=blue]car[/color] ([color=blue]entsel[/color])))
       (toggleflipstate ([color=blue]vlax-ename->vla-object[/color] obj))
   )
   ([color=blue]princ[/color])
)
([color=blue]vl-load-com[/color]) ([color=blue]princ[/color])

Share this post


Link to post
Share on other sites
TheyCallMeJohn

Lee Mac,

I have multiple flips states. Is there a way to pass it a the name and the parameter I want to set it to? Some are accesible by the user and some are not as they are controlled by lookup parameters.

 

FlipState.png

Share this post


Link to post
Share on other sites
Lee Mac
Lee Mac,

I have multiple flips states. Is there a way to pass it a the name and the parameter I want to set it to? Some are accesible by the user and some are not as they are controlled by lookup parameters.

 

Sure, in general you could use my Set Dynamic Property Value function.

 

For your case:

(LM:SetDynamicPropValue <VLA-Object> "UB_FLIP" 1)

or:

(LM:SetDynamicPropValue <VLA-Object> "UB_FLIP" 0)

Share this post


Link to post
Share on other sites
chowter

Hi, i have some problems with set flip parameters. I used yours "Set Dynamic Property Value" Code and:

 

(LM:SetDynamicPropValue <VLA-Object> "Flip_state0" 1)
(LM:SetDynamicPropValue <VLA-Object> "Flip_state1" 1)

After running the script appeared error:

 

Error: bad argument type: VLA-OBJECT nil

 

My flip parameter names:

Flip_state0

Flip_state1

 

My dynamic block name:

F_MOD_DIP_SW_HORIZONTAL

 

I need some assistance...

Share this post


Link to post
Share on other sites
Lee Mac

The first argument must be a valid VLA-Object - see my earlier example program for how to supply a VLA-Object to a function.

Share this post


Link to post
Share on other sites
BrianTFC

Lee,

I know this is an old thread but, is there a way to make the code to where you can flip multiple blocks by window selecting them?

 

([color=blue]defun[/color] c:flip ( [color=blue]/[/color] obj )
   ([color=blue]if[/color] ([color=blue]setq[/color] obj ([color=blue]car[/color] ([color=blue]entsel[/color])))
       (toggleflipstate ([color=blue]vlax-ename->vla-object[/color] obj))
   )
   ([color=blue]princ[/color])
)
([color=blue]vl-load-com[/color]) ([color=blue]princ[/color])

Share this post


Link to post
Share on other sites
Lee Mac
Lee,I know this is an old thread but, is there a way to make the code to where you can flip multiple blocks by window selecting them?

 

Certainly - please try the following:

(defun c:flip ( / i s )
   (if (setq s (ssget "_:L" '((0 . "INSERT"))))
       (repeat (setq i (sslength s))
           (LM:toggleflipstate (vlax-ename->vla-object (ssname s (setq i (1- i)))))
       )
   )
   (princ)
)

;; Toggle Dynamic Block Flip State  -  Lee Mac
;; Toggles the Flip parameter if present in a supplied Dynamic Block.
;; blk - [vla] VLA Dynamic Block Reference object
;; Return: [int] New Flip Parameter value

(defun LM:toggleflipstate ( blk )
   (vl-some
      '(lambda ( prp / rtn )
           (if (equal '(0 1) (vlax-get prp 'allowedvalues))
               (progn
                   (vla-put-value prp (vlax-make-variant (setq rtn (- 1 (vlax-get prp 'value))) vlax-vbinteger))
                   rtn
               )
           )
       )
       (vlax-invoke blk 'getdynamicblockproperties)
   )
)

(vl-load-com) (princ)

Toggle Flip State function from here.

Share this post


Link to post
Share on other sites
Louderjohn

Lee,

Does your Flip.lsp program flip only the first Flip parameter encountered? What if there are more than one flip parameters defined in the dynamic block?

Share this post


Link to post
Share on other sites
BrianTFC

Lee,

 

Thank you so much!!!! :beer:

 

Brian

Share this post


Link to post
Share on other sites
Lee Mac
Lee,

Does your Flip.lsp program flip only the first Flip parameter encountered? What if there are more than one flip parameters defined in the dynamic block?

 

Currently yes - change vl-some to mapcar to toggle all Flip parameters held by the block. :thumbsup:

 

Lee,

 

Thank you so much!!!! :beer:

 

Brian

 

You're welcome!

Share this post


Link to post
Share on other sites
halam

I like it and probably is a good reason to give blocks a flip parameter

With more dynamic feature it fails unexpected.

(tested only a little bit...)

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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