Need example of code for inserting a dynamic block and changing a param

Need example of code for inserting a dynamic block and changing a param

acadadmin3KNUF
Advocate Advocate
2,646 Views
9 Replies
Message 1 of 10

Need example of code for inserting a dynamic block and changing a param

acadadmin3KNUF
Advocate
Advocate

Hello to all:

 

Could someone please help me out with some example code...  I need to use LISP to:

1) grab a dynamic block named "ExampleBlock" from "ExampleDwg" located at C:\New folder 

2) Change the parameter in that block named "DistanceOne" from a previously-set value to 21   

3) insert with mouse click in the current dwg

 

Thanks very much for any help.  I have a large library of blocks organized by width.  It would be VERY helpful if I only had to maintain ONE set of blocks.  Right now, if a problem is discovered, I have to go back and modify at least seven different width-variants.  If I could just have my users insert ONE block from a tool palette with a width that could be entered beforehand (I will work on that coding later) it would make my life SOOOO much easier.  Thanks in advance!

0 Likes
Accepted solutions (1)
2,647 Views
9 Replies
Replies (9)
Message 2 of 10

Sea-Haven
Mentor
Mentor

As you want from palette can be done pretty easy, you need to have 1 lisp loaded either autoloaded or as part of the palette command.

 

 

(load "dynam blk.lsp")(dynam "xxx" prp value)

 

So the lisp has a defun dynam passing the block name which can be "C:\\New folder\\Exampledwg\\ExampleBlock" the "size"  would be a number. The prp is the block parameter name.

 

You also need Lee-mac Dynamic block lisp for the put value into a block. 

 

;Thanks to Lee for dynamic block stuff

(defun LM:setdynpropvalue ( blk prp val )

 

If you get stuck post again.

0 Likes
Message 3 of 10

pbejse
Mentor
Mentor

@acadadmin3KNUF wrote:

1) grab a dynamic block named "ExampleBlock" from "ExampleDwg" located at C:\New folder 

2) Change the parameter in that block named "DistanceOne" from a previously-set value to 21   

3) insert with mouse click in the current dwg

All can be done thru Tool Palette

pbejse_0-1643895474461.png

Create a copy on the tool palette per Custom values and the n you're good to go.

 

0 Likes
Message 4 of 10

ВeekeeCZ
Consultant
Consultant
Accepted solution

See the example below. 

Credit for all the hard work one this belongs to Lee Mac. I just did minor adjustments.

HTH

Message 5 of 10

acadadmin3KNUF
Advocate
Advocate

Hello: 

Thanks very much for your contribution...but It is not functioning correctly yet.  I've attached an updated verson of your file, the dwg with the ExampleBlock, and a screenshot showing the block's name, the parameter's name, and the file location.  In your program, i tweaked the "if failure" line to spit out some text that says "no this didnt work yet" rather than just simply exiting.

 

I have spent the fast few hours constantly searching, and all I seem to find is "the user is prompted to select from a list..."

NO!  That's NOT what I want.  I don't want the user prompted to select ANYTHING except the block's insertion point and insertion rotation.  That's the whole point of this post, I want to define most of the parameters BEFOREHAND.

 

I understand perfectly how Lee Mac's "Set Dynamic Properties" works.  I have about 35 blocks that are on this tool palette,, so I need a button for each one that runs code which will populate SEVERAL of this kind of statement.  For example:

(LM:setdynpropvalue obj "BF" (15))
(LM:setdynpropvalue obj "SWITCH: CONTROLS SIDE" (LH CONTROLS))

In this example, the block would be inserted AUTOMATICALLY with "BF" set to "15" and "SWITCH: CONTROLS SIDE" set to "LH-CONTROLS", and the user would be asked for the insertion point and rotation ONLY.

 

I know this is possible.  I'm soooo close it's getting even more frustrating.  Thanks in advance for any continued help!

0 Likes
Message 6 of 10

ВeekeeCZ
Consultant
Consultant

Code updated. As usual, just minor inconsistency. Sorry about that.

0 Likes
Message 7 of 10

acadadmin3KNUF
Advocate
Advocate

Hello, thanks for the update message.  I'm not seeing any file attached to your updated reply, can you check again?  Thanks so much for your help! 😁

0 Likes
Message 8 of 10

pbejse
Mentor
Mentor

@acadadmin3KNUF wrote:

Hello, thanks for the update message.  I'm not seeing any file attached to your updated reply, can you check again?  Thanks so much for your help! 😁


 

That means attached code at post #4 is updated @acadadmin3KNUF 

This

 

(BLM:importblock path "block")

 

To

 

(BLM:importblock path block)

 

HTH

 

Message 9 of 10

acadadmin3KNUF
Advocate
Advocate

THERE we go! Fantastic, thanks! 😁

0 Likes
Message 10 of 10

pbejse
Mentor
Mentor

@acadadmin3KNUF wrote:

THERE we go! Fantastic, thanks! 😁


Glad it works for you, the credit goes to Z9E3zK5E at post #4 

You are welcome nonetheless @acadadmin3KNUF  🙂

 

[ switched ]  All is right again 🙂

 

0 Likes