Jump to content

Editing block with lisp


Lukijan

Recommended Posts

I know I'm not first one who starts this topic, but I didn't find answer how to solve problem that I have. (I'm from Serbia, so my English could be bad)

 

I have to write lisp code that would get block last inserted block and edit it (have to change length of two lines).

 

Another way is to take block from my base of blocks and edit it before inserting it.

 

Can someone help me with this? I have headache for days :S

Link to comment
Share on other sites

Well, I have to make lisp program that would ask user for two points, calculate distance and angle between them and insert "pipelike" block with edited length (new length would be distance between these points).

Link to comment
Share on other sites

Well, I have to make lisp program that would ask user for two points, calculate distance and angle between them and insert "pipelike" block with edited length (new length would be distance between these points).

 

Make your 'pipelike' block to have the correctly defined width, and a length of 1 unit in the positive X-direction; then, when inserting the block, you can scale and rotate the block according to the selected points without the need to edit the block definition. Though note that this would result in non-uniformly scaled blocks present in your drawing.

 

Otherwise, look into using Dynamic Blocks with a Stretch Parameter.

Link to comment
Share on other sites

I can't scale it or stretch it... here is my block, I have only to change length of these two the longest lines.

 

here is what I basically have for now:

 

(defun dtr (a)
(* pi (/ a 180))
)

(defun c:cevproba ()
(setq b(getpoint "\nFirst point"))
(setq c(getpoint "\nSecond point"))
(setq l(distance b c))
(setq ang(dtr(angle b c)))
(setq ang1(+ ang 90))

(command "_.-insert" "cev50" "R" ang1 "x" 1 "y" 1 "z" 1 b)

)

 

and the block "cev50" is in attachments.

cev50.dwg

Link to comment
Share on other sites

Here is an example of the above idea:

 

PipeBlock.gif

 

[color=GREEN];; Pipe Block  -  Lee Mac 2012[/color]
[color=GREEN];; Inserts a unit length block scaled in the x-direction and[/color]
[color=GREEN];; rotated to align with two selected points.[/color]

([color=BLUE]defun[/color] c:pipe ( [color=BLUE]/[/color] bf bn cm nm p1 p2 )

   ([color=BLUE]setq[/color] bn [color=MAROON]"pipe"[/color]) [color=GREEN];; Pipe Block Name[/color]

   ([color=BLUE]cond[/color]
       (   ([color=BLUE]not[/color]
               ([color=BLUE]or[/color] ([color=BLUE]tblsearch[/color] [color=MAROON]"BLOCK"[/color] bn)
                   ([color=BLUE]and[/color]
                       ([color=BLUE]setq[/color] bf ([color=BLUE]findfile[/color] ([color=BLUE]strcat[/color] bn [color=MAROON]".dwg"[/color])))
                       ([color=BLUE]progn[/color]
                           ([color=BLUE]setq[/color] cm ([color=BLUE]getvar[/color] 'cmdecho))
                           ([color=BLUE]setvar[/color] 'cmdecho 0)
                           ([color=BLUE]command[/color] [color=MAROON]"_.-insert"[/color] bf [color=BLUE]nil[/color])
                           ([color=BLUE]setvar[/color] 'cmdecho cm)
                           ([color=BLUE]tblsearch[/color] [color=MAROON]"BLOCK"[/color] bn)
                       )
                   )
               )
           )
           ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\n"[/color] bn [color=MAROON]" block not found."[/color]))
       )
       (   ([color=BLUE]and[/color]
               ([color=BLUE]setq[/color] p1 ([color=BLUE]getpoint[/color] [color=MAROON]"\nSpecify 1st Point: "[/color]))
               ([color=BLUE]setq[/color] p2 ([color=BLUE]getpoint[/color] [color=MAROON]"\nSpecify 2nd Point: "[/color] p1))
           )
           ([color=BLUE]setq[/color] nm ([color=BLUE]trans[/color] '(0.0 0.0 1.0) 1 0 [color=BLUE]t[/color]))
           ([color=BLUE]entmake[/color]
               ([color=BLUE]list[/color]
                  '(0 . [color=MAROON]"INSERT"[/color])
                   ([color=BLUE]cons[/color] 2 bn)
                   ([color=BLUE]cons[/color] 10 ([color=BLUE]trans[/color] p1 1 nm))
                   ([color=BLUE]cons[/color] 50 ([color=BLUE]angle[/color] p1 p2))
                   ([color=BLUE]cons[/color] 41 ([color=BLUE]distance[/color] p1 p2))
                   ([color=BLUE]cons[/color] 210 nm)
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)

Change the block name to suit.

Link to comment
Share on other sites

I can't scale it or stretch it... here is my block, I have only to change length of these two the longest lines.

 

In that case, I would strongly recommend converting the Block to a Dynamic Block and adding a Stretch Parameter to the two longest lines, otherwise, your code would need to copy and modify the pipe block definition everytime a block is inserted. This is effectively what happens with a Dynamic Block (when modifed, the reference becomes anonymous with a new block definition), however, with a Dynamic Block, this functionality is already present and doesn't need to be recreated in LISP.

Link to comment
Share on other sites

Here is a demonstration after quickly converting your uploaded Block to be a Dynamic Block:

 

PipeDynBlock.gif

 

I have added a Stretch Parameter and Rotation Parameter for convenience. If I spent more time on it, I would include the Rotation Parameter in the set of objects for the Stretch Parameter, so that the Rotation control moves with the Stretch control.

Link to comment
Share on other sites

Oh! Thank you very much, I'm still new in all of this and I don't know all options that CAD programs offer. Thanks again!

 

You're very welcome :)

 

I recommend that you spend some time studying Dynamic Blocks - they are very powerful!

Link to comment
Share on other sites

Problem, again. Maybe wrong place, but still...

 

I'm not using AutoCAD but ProgeCAD and it seems that dynamic blocks work only in AutoCAD. Can you help me with that or I must ask for help somewhere else? :S

Link to comment
Share on other sites

Unfortunately I don't think ProgeCAD has dynamic blocks at all. If I'm guessing correct, ProgreCAD is a spinoff of IntelliCAD, same as BricsCAD is. And I know BC has only recently attempted adding DynBlks, still some issues though.

 

How about generating the block definition from scratch? You could use entmake to first make the "BLOCK", then all the linework inside (adjusting some lengths to suit), then an "ENDBLOCK" ... after which you can then insert that block. For a sample see here: http://autocad.wikia.com/wiki/Entmaking_block_definitions

 

I'd just advise keeping the block name unique. Perhaps have a suffix to indicate the length. Otherwise you could redefine the 1st placement with a new definition (i.e. only the last placed block would look correct).

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