Jump to content

Inserting block under angle to a midpoint of a line!help?


Recommended Posts

Posted

Hello to everyone,

 

I'm at the beginning of learning lisp, so I'll need some help with inserting a block...

I have a block (which I want to insert) stored in dwg format and I want to insert that block to a midpoint of selected line (you can see a result I want in attached image).

My block consists of 2 parallel lines and I want them to be inserted to a midpoint of a selected line in a way they are prependicular to selected line.

I have found something like this so far...it's not bad, but I would like to select a line instead of insertion point, and with this lisp user define angle of insertion and I want my block lines always to be prependicular to selected line.

I like in this example that when I start command I don't have to open my block first and after one block is inserted that I stay in command so I can insert another one.

 

(defun c:MyBlock (/ pt)
 (while (setq pt (getpoint "\nPick Insertion point."))
   (command "-insert" "name_of_my_block" "_non" pt "" pause)
 )
 (princ)
)

 

So if someone can help me I would be very grateful...

example.jpg

Posted

Perhaps:

 

(defun c:ins (/ *error* bNme doc spc ent uflag mpt ang)
 (vl-load-com)

 (setq bNme "test" ) ;; Block Name

 (defun *error* (msg)
   (and uflag (vla-EndUndoMark doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))         

 (setq doc (vla-get-ActiveDocument
             (vlax-get-Acad-Object))
       
       spc (if (zerop
                 (vla-get-activespace doc))
             (if (= (vla-get-mspace doc) :vlax-true)
               (vla-get-modelspace doc)
               (vla-get-paperspace doc))
             (vla-get-modelspace doc)))

 (if (or (tblsearch "BLOCK" bNme)
         (setq bNme (findfile (strcat bNme ".dwg"))))

   (while
     (progn
       (setq ent (entsel "\nPick Line for insertion: "))

       (cond (  (eq 'ENAME (type (car ent)))

                (if (vl-catch-all-error-p
                      (vl-catch-all-apply 'vlax-curve-getEndParam (list (car ent))))

                  (princ "\n** Invalid Object Selected **")

                  (progn
                    (setq uflag (not (vla-StartUndoMark doc)))

                    (setq mpt (vlax-curve-getPointatParam (car ent)
                                (/ (vlax-curve-getEndParam (car ent)) 2.))
                          
                          ang (angle '(0 0 0) (vlax-curve-getFirstDeriv (car ent)
                                                (vlax-curve-getParamatPoint (car ent) mpt))))

                    (vla-InsertBlock spc (vlax-3D-point mpt) bNme 1. 1. 1. ang)

                    (setq uflag (vla-EndUndoMark doc)) t))))))

   (princ "\n** Block Definition not Found **"))

 (princ))

Posted

This is very close...but lines of my block are parallel with line and they should be prependicular to a line of insertion. (here's a image of a result now)

And is it possible to select more lines at once so block is inserted to each line with executing command only once...or after block is inserted to selected line I can select another line?

 

Thanx for help...I really appreciate!

 

P.S.

 

Just noticed that it doesn't insert block to midpoint of a line, block is inserted to a point where I select line...

result.jpg

Posted

I don't know the orientation of your block. The code that I have posted will insert the block with a rotation that is perpendicular to the tangent vector at the point clicked on the object.

 

As for the repeat - that was meant to be there, just missed a "t" :P

 

Lee

Posted

Just noticed that it doesn't insert block to midpoint of a line, block is inserted to a point where I select line...

 

Sorry, I should probably read a bit more... didn't realise it was the midpoint... :oops:

Posted

My block is placed like this...it's vertical...if this help's you...

block.jpg

Posted

You're the man!!!

It works!!!

 

Thanks a lot!

Posted

Or maybe using a little older style:

 

[b][color=BLACK]([/color][/b]defun c:inmp [b][color=FUCHSIA]([/color][/b]/ ss en ed p10 p11 mp[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]setq ss [b][color=GREEN]([/color][/b]ssget '[b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]0 . [color=#2f4f4f]"LINE"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]= [b][color=GREEN]([/color][/b]sslength ss[b][color=GREEN])[/color][/b] 1[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq en [b][color=MAROON]([/color][/b]ssname ss 0[b][color=MAROON])[/color][/b]
              ed [b][color=MAROON]([/color][/b]entget en[b][color=MAROON])[/color][/b]
              p10 [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 10 ed[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              p11 [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 11 ed[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              mp [b][color=MAROON]([/color][/b]mapcar '[b][color=GREEN]([/color][/b]lambda [b][color=BLUE]([/color][/b]a b[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]* [b][color=RED]([/color][/b]+ a b[b][color=RED])[/color][/b] 0.5[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] p10 p11[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]command [color=#2f4f4f]"_.INSERT"[/color] [color=#2f4f4f]"test"[/color] mp 1 1 [b][color=MAROON]([/color][/b]/ [b][color=GREEN]([/color][/b]* [b][color=BLUE]([/color][/b]+ [b][color=RED]([/color][/b]* pi 0.5[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]angle p10 p11[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] 180.0[b][color=GREEN])[/color][/b] pi[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

-David

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