Jump to content
subodh_gis

Insert Block in-between two Points using Autolisp

Recommended Posts

subodh_gis

Many a times it requires to show the same block with different angle and scale. Rotating each block to a required angle, and scaling it as required will take a lot of time so can we Insert Block in-between two Points in the angle and scale of points selection using Autolisp . I am using AutoCAD 2004.

Thank You !

Share this post


Link to post
Share on other sites
satishrajdev

Can you a show any example for this

Share this post


Link to post
Share on other sites
gS7

Try This . I Hope Its Help You ...

Tested in 2004 version


(defun c:Test(/ b ss e en xe ye ze r)
  ;Ganesh Shetty
  ;Match Block Rotation angle & Scale
  ;2013
  (vl-load-com)
  (if
    (and
        (setq B (car (entsel"\nSelect Block:")))
 (setq ss (ssget '((0 . "INSERT"))))
    )
    (progn
          (setq e (vlax-ename->vla-object b))
          (repeat (setq i (sslength ss))
     (setq en (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
     (setq XE (vla-get-XScaleFactor e)
	   YE (vla-get-YScaleFactor e)
	   ZE (vla-get-ZScaleFactor e)
	   r  (vla-get-Rotation e)
     )
     (if (vlax-method-applicable-p en 'Rotate)
       (vla-put-rotation en r)
     )
     (vla-put-XScaleFactor en XE)
     (vla-put-YScaleFactor en YE)
     (vla-put-ZScaleFactor en ZE)
   )
      )
   )
 (princ))

Share this post


Link to post
Share on other sites
subodh_gis

@ Ganesh Shetty

 

Thanks for quick reply sir

What it will do sir? Its asking to select the block and object.

Please explain how it will help me.

Share this post


Link to post
Share on other sites
satishrajdev

Dear Subodh,

 

R u want a lisp, that can insert block with specific rotation and scale???

 

or

 

You want to change rotation and scale of existing block???

Share this post


Link to post
Share on other sites
subodh_gis

I want a lisp that can insert a perticular block with rotation and scale using two clicks only BLOCK.JPG

Share this post


Link to post
Share on other sites
satishrajdev

Here is a example for this, I hope this would help you :-

 

(Defun c:test ()

 (setq	ent    (car (entsel "\n Select Block :"))
bkname (cdr (assoc 2 (entget ent)))
rotp1  (getpoint "\n Specify 1st Rotation point :")
rotp2  (getpoint "\n Specify 2nd Rotation point :")
rot    (angle rotp1 rotp2)
scl    (distance rotp1 rotp2)
pnt    (getpoint "\n Specify Point to Insert Block :")
 )

 (command "insert" bkname "_scale" scl "_non" pnt rot)

 (princ)
)

Share this post


Link to post
Share on other sites
gS7
@ Ganesh Shetty

 

Thanks for quick reply sir

What it will do sir? Its asking to select the block and object.

Please explain how it will help me.

 

Kindly find the attached Drawing file for Program Guide

 

match block.dwg

Share this post


Link to post
Share on other sites
neophoible

Are you saying that the insertion point of your BLOCK will match the midpoint of your two picked points? If so, then that will be an easy fix for the routine already offered. If the scale is simply the distance from one of the pick points to the calculated insertion point, then that should not be too difficult to add as well. Is that the scale factor you need?

Share this post


Link to post
Share on other sites
gS7

@subodh,

Are You Going to Insert Different Types of Blocks ?

Kindly attach Your Block Drawing..

We are Trying to Help You ,Don't be sad

Share this post


Link to post
Share on other sites
gS7

I found a Solution ,

 

1.Make Sure Your Block Dimensions is 1mm x 1mm Size

2.Make Center Point is Your Block Insertion Point

Codes.

(defun c:Test(/ bname pt1 pt2 d ang mp)
 (if
   (and
      (setq bname(getstring "\nEnter Block Name To Insert:"))
      (setq pt1 (getpoint "\nPick First Rotation Point:"))
      (setq pt2  (getpoint "\nPick 2nd Rotation Point:"))
   )
   (progn
  (if (not (Tblsearch "BLOCK" bname))
    (princ "\nBlock Not found in Drawing!")
    (progn
      (setq d (/ (distance pt1 pt2) 2.0))
             (setq ang (angle pt1 pt2))
      (setq mp (polar pt1 ang d))
      (command "_INSERT" bname "_SCALE" (distance pt1 pt2) "_non" mp (angtos ang))
    )
  )
     )
   )
 (princ))

 

 

Here , Find the attachment Drawing .. your Block Should Be Like This

 

Myblock.dwg

Share this post


Link to post
Share on other sites
javid

Hello dear friends:)

I read this useful post but I have a problem with this lisp...

As I tried to changing this routine for myself and i didn't succeed! :(

I need your help to have another lisp withoput changing my block scale and also without asking my block name each times i want to use this lisp (I want to write my blockname directly into that lisp).

So, I need to use just one block in to my drawing only with changing it's rotation.

I will be thankful if anybody help me to solve my problem.

Share this post


Link to post
Share on other sites
JamCAD

javid, here is a very basic version for you to try. It will only insert the block if it already exists in the drawing

(defun c:blockmp (/ blknme p1 p2 ang)
 (setq blknme "Name of block")            ;Name of the block
 (setq p1 (getpoint "\nPick first point: "))
 (setq p2 (getpoint p1 "\nPick second point: "))
 (setq ang (angtos (angle p1 p2)))    ;Calculates the angle between points one and two
 (command "_Insert" blknme "_mtp" p1 p2 1 "" ang)
)

  • Like 1

Share this post


Link to post
Share on other sites
javid

Hi dear j0nat :)

Thank you so much for your useful help

It's working for me anf was so helpful

Thanks alot:)

Share this post


Link to post
Share on other sites
svippala
@JamCAD
Thanks for coding 
in the same code we adding scale(up/down) option is its possible  


(defun c:blockmp (/ blknme p1 p2 ang)
 (setq blknme "Name of block")            ;Name of the block
 (setq p1 (getpoint "\nPick first point: "))
 (setq p2 (getpoint p1 "\nPick second point: "))
 (setq ang (angtos (angle p1 p2)))    ;Calculates the angle between points one and two
 (command "_Insert" blknme "_mtp" p1 p2 1 "" ang)
)

 

 

 

 

 

 

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