Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

trying to insert block at specifid distance (Code example supplied)

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
309 Views, 3 Replies

trying to insert block at specifid distance (Code example supplied)

Its been a while since Ive used lisp none the less my appologies if the attempetd code looks a little wierd..

 

What I want to achive is inserting a block and moving it at a specified distance.

 

My code:

 

(defun c:MYTEST (/ MYPOINT)

      (setq MYDIST (getint "\nOffset distance: "))
  (while (setq MYPOINT (getpoint "\nPick Insertion point."))
(setq INSPOINT (MYPOINT + MYDIST))

    (command "-insert" "C:/ICT/AutoCAD_Architecture_suite_2012/Blocks/Gebr Bodegraven BV/Ankers/GB-Ankers_1.dwg" "_non" INSPOINT "" "" pause)
  )
  (princ)
)

 

also what I cant figure out is how can I insert a block (By name) contained with in my dwg file rather then just insert the whole DWG as one block?

3 REPLIES 3
Message 2 of 4
_gile
in reply to: Anonymous

(setq INSPOINT (MYPOINT + MYDIST))

 This won't work.

LISP uses prefixed notation (function [argument] ...).

And you cannot add an integer to a point (a list of 3 numbers).

 

If the block in in the drawing block table, just call it with its name.

 

(command "_insert" "GB-Ankers_1" "_non" INSPOINT "" "" pause)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 4
Kent1Cooper
in reply to: Anonymous

In addition to _gile's comments, you need to be more specific about the new location -- it needs to be in some direction from the MYPOINT location.  If that direction is always the same, you can build it into the routine.  For instance if you want all Blocks inserted that distance to the right of the picked point:

 

(defun c:MYTEST (/ MYPOINT)
  (setq MYDIST (getint "\nOffset distance: "))
  (while (setq MYPOINT (getpoint "\nPick Insertion point."))
    (command "_.insert" "GB-Ankers_1" "_non" (polar MYPOINT 0 MYDIST) "" "" pause)
  )
  (princ)
)

 

Replace the 0 with any angle in radians.  If the relative direction should not always be the same, some other approach would be needed.

 

I would also suggest using (getdist) rather than (getint).  If you do, the User can type in a value, but they can instead, if they prefer, pick two points on-screen [which will return the distance but not the direction between them], and they can enter a value in length-units format [e.g. in Imperial Architectural format, 5'3 1/2", which (getint) will not accept].

Kent Cooper, AIA
Message 4 of 4
stevor
in reply to: Anonymous

In addition to what they said:
if you use such routines frequently,
you may find saving the 'MYDIST'

 as a global type variable,

and reusing it by various methods

 

Ie:

 ; GET_D
 (defun get_d (d s / ans ) (setq d (if d d 0.0)
      ans (getdist (strcat " " s " < " (rtos d 2 4) " > ")))
   (if ans ans d) )

 

And use

(setq My*Dist (Get_D My*Dist "\n Offset distance: "))

 

in place of:
(setq MYDIST (getint "\nOffset distance: "))

 

The  * chacter only tells me that it is a global,

like a star in the sky;

any legal variable name works.

 

S

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost