Jump to content

Lisp insert a dynamic block


woodman78

Recommended Posts

I want to insert a dynamic block with a lisp and make use of the alignment feature of the block on insertion. This is what I normally use to insert a block:

 

                 (if (setq pt (setq INPT (getpoint "\nPick Insertion Point: ")))
                (command "_.-insert" block INPT "1" "1" "0"))))

 

I want to insert the block but instead of selecting the INPT before running the command I want to be able to choose the point on screen and have the block rotate to match a line based on the alignment feature.

 

How to I do this?

Link to comment
Share on other sites

You can do it like this .... :)

 

(defun c:test (/ name o e p1 p2 ins)
;; Tharwat 01. 07. 2011
 (if (and (setq name (getstring T "\n Name of Block to insert :"))
          (tblsearch "BLOCK" name)
          (setq o (entsel "\n Select Line :"))
          (eq (cdr (assoc 0 (setq e (entget (car o))))) "LINE")
     )
   (progn
     (setq p1 (cdr (assoc 10 e))
           p2 (cdr (assoc 11 e))
     )
     (command "_.-insert" name p1 1. 1. 0.)
     (command "_.align"
              (entlast)
              ""
              (setq ins (cdr (assoc 10 (entget (entlast)))))
              p1
              (list (car ins) (+ (cadr ins) 0.5) 0.)
              p2
              ""
              ""
     )
     (redraw)
   )
   (princ "\n Block not found or Selection is not a line !! ")
 )
 (princ)
)

 

Tharwat

Link to comment
Share on other sites

Thanks Tharwat,

 

I am trying to draw a pline and insert the block after that. I have modified your code to give me this but it can't find the block. Any ideas?

 

(defun c:Guy_Rope (/ name o e p1 p2 ins)
;; Tharwat 01. 07. 2011
 
(command "_.-layer" "_N" "CCC_SURVEY_Existing Stay or Guy Rope" "_M" "CCC_SURVEY_Existing Stay or Guy Rope" "_C" "1" "CCC_SURVEY_Existing Stay or Guy Rope" "" )
(command "._pline")
(if (and (setq name "Guy_Rope_Survey")
          (tblsearch "BLOCK" name)
          (setq o (entsel "\n Select Line :"))
          (eq (cdr (assoc 0 (setq e (entget (car o))))) "LINE")
     )
   (progn
     (setq p1 (cdr (assoc 10 e))
           p2 (cdr (assoc 11 e))
     )
     (command "_.-insert" name p1 "1" "1" "0")
     (command "_.align"
              (entlast)
              ""
              (setq ins (cdr (assoc 10 (entget (entlast)))))
              p1
              (list (car ins) (+ (cadr ins) 0.5) 0.)
              p2
              ""
              ""
     )
     (redraw)
   )
   (princ "\n Block not found or Selection is not a line !! ")
 )
 (princ)
)

Link to comment
Share on other sites

It won't work because Polyline is different than line and why did you change the idea of your first thread ?

 

Entity line has only start and end points , but polyline is completely different than that

Link to comment
Share on other sites

Well, I didn't realise there was that big a difference. Anyway I ran your routine and it does work with a pline. But it didn't do what I wanted so I went back and wrote it again from scratch. This is what I have now:

(defun c:guy_rope1 (/ pline SUCE SUSM SUCL SUCR rope_block)
(setq SUCE (getvar "cmdecho"))  
(setq SUSM (getvar "osmode"))
(setq SUCL (getvar "clayer"))
(setq SUCR (getvar "cecolor"))

(setq vl1 (list
       (cons 0 "LAYER")        ;Name of entity
       (cons 100 "AcDbSymbolTableRecord")                    ;Open Records
       (cons 100 "AcDbLayerTableRecord")                    ;Locate Layer Table
       (cons 2 "CCC_SURVEY_Existing Stay or Guy Rope")        ;Name of Layer
       (cons 62 1)                            ;colour = light grey
       (cons 70 0)                            ;state
       (cons 290 1)                            ;1=plot, 0=Don't plot
           )                            ;End of entity list
       )
       (entmake vl1)

(setvar "clayer" "CCC_SURVEY_Existing Stay or Guy Rope")  
(setvar "cecolor" "Bylayer")  
 
(princ "\nDraw an stay or guy rope line: ")
(setvar "plinegen" 1)
(command "._pline")
(while (= 1 (logand 1 (getvar "cmdactive")))
(command pause))
(setq pline (entlast)
elist (entget pline)
)
(setq name "guy_rope_survey")
(command ".-Insert" name pause pause "" )
(setq rope_block (entlast)
elist (entget rope_block)
)
(command "explode" rope_block)
(setvar "cmdecho"   SUCE)
(setvar "osmode" SUSM)
(setvar "clayer" SUCL)
(setvar "cecolor" SUCR)
 (princ)
)

 

I am having a few issues that maybe someone can help me with. This is the command dump for the first aprt of the routine:

Command: guy_rope1

 

Draw an stay or guy rope line: ._pline

Specify start point:

Current line-width is 0.0000

Specify next point or [Arc/Halfwidth/Length/Undo/Width]:

Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:

 

Why does that ._pline show up?

My variables for layers aren't being reset. My layer is not setting back to the original value.

And does anyone have a better way of running the insert so that it allows the user to make use of the alignment feature of the dynamic block without having to right click to finish the command?

 

Thanks

Link to comment
Share on other sites

Have you considered using the vla-insertBlock Method instead, then simply stepping through the Dynamic Block Object's properties (i.e. Visibility States, Attributes, etc.)? It's really quite simple, and less (if any?) SysVars need storing / restoring.

 

(^^ It's what I do for my Dynamic Title Blocks ^^)

Link to comment
Share on other sites

Look at my attached code. In particular the Blocks:GetParameters, Blocks:GetParam, Blocks:GetParamValue and Blocks:PutParamValue functions.

 

Other than that, you need to get hold of the vla Model/Paper space object to use its vla-InsertBlock method. Look in the Developer Help under ActiveX/COM.

BlockData.LSP

Link to comment
Share on other sites

No I haven't RenderMan. Sounds very interesting though. How do I do that?

 

Irneb has taken the time to provide you with some of his functions to assist you.

 

If you're unable to decipher what's needed between those functions and the developer help, post back with your question(s), and perhaps a copy of your dynamic block.

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