Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Auto draw object

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
aliff_ahtenk
1356 Views, 12 Replies

Auto draw object

Hi all, can anybody help me on this, I want to use this object as lisp, but I don't know how to start.

I want to take a starting point at block point.

then it auto draw the object,

the object is selected and rescale for some size,

then block with scale code name,

then finally object is select again to choose direction to place..

Thank you in advance.

12 REPLIES 12
Message 2 of 13
j.palmeL29YX
in reply to: aliff_ahtenk

What is the goal of this task? Why do you want to draw it with LISP if you have it already drawn. 

You can add some dynamic parameters and actions for quick scaling and placing the block.

What do you mean with "then block with scale code name"?

 

 

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 3 of 13
aliff_ahtenk
in reply to: j.palmeL29YX

it is because i dont want to store in the template. so i just make one lisp, a single command, insert size and rotate.. so the object will be make itself.

Message 4 of 13
j.palmeL29YX
in reply to: aliff_ahtenk


@aliff_ahtenk wrote:

it is because i dont want to store in the template.


You can store it anywhere. Then insert this as block (using the insert command, or drag it into your current drawing, or use the DesignCenter, or use a Toolpalette, or ... what you want).

 

 

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 5 of 13
aliff_ahtenk
in reply to: j.palmeL29YX

yup, that is the method that i currently use. tq. class dismiss.

Message 6 of 13
RobDraw
in reply to: aliff_ahtenk

If you already know how you should be doing it, why did you ask for a LISP?

 

BTW, there is a separate forum for LISP and other customizations.


Rob

Drafting is a breeze and Revit doesn't always work the way you think it should.
Message 7 of 13
j.palmeL29YX
in reply to: aliff_ahtenk


@aliff_ahtenk wrote:

... that is the method that i currently use.


That you didn't tell us ... 

 

Well. If you urgently want to use a LISP, here an (simplified and rough) example how you can do it:

 

 

 

(defun c:test (/)
  (setq P0 (getpoint "\nWhere to insert: "))
  (setq SF (getdist "\nScale factor: "))
  (setq RA (getreal "\nRotation angle: "))
  (setq ss (ssadd))  ; create selection set

  (command "_arc" "_C" '(-1090 0) '(-346 -175) '(-346 175))   ; 1st arc
  (ssadd (entlast) ss)   ; add to selection set
  (command "_arc" "_C" '(-796.5 0) '(-305.5 -198) '(-305.5 198))  ; 2nd arc
  (ssadd (entlast) ss)   ; add to selection set
;;; ...   repeat for all arc's

  (command "_line" '(-346 -175) '(-305.5 -198) "")
  (ssadd (entlast) ss)
  (command "_line" '(-346 175) '(-305.5 198) "")
  (ssadd (entlast) ss)
;;; ... repeat for all lines
;; if complete geometry is drawn, modify it (move, scale, rotate)
  (command "_move" ss "" '(0 0) P0)
  (command "_scale" ss "" p0 sf)
  (command "rotate" ss "" p0 ra)
  (princ)
 )

;; HTH for a beginning

 

 

 

 

It does the job for the first 2 arcs and their connecting lines (the dimensions of the geometry were rounded) . You can complete it yourselfe for the remaining arcs and lines.

 

But again: I can not understand why you don't want to use the current method (insert block). What advantages or improvements do you expect from a LISP routine?

 

(And I still don't know what is "then block with scale code name," ?)

 

 

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 8 of 13
Kent1Cooper
in reply to: j.palmeL29YX


@j.palmeL29YX wrote:

....

(And I still don't know what is "then block with scale code name," ?)


I think they want, after scaling the drawn results [the line before that], to define them as a Block whose name includes an indication of the scale.  Then they could have separate Blocks with the scale- or size-indication difference in otherwise the same Block name, in the same drawing.  @aliff_ahtenk , is that correct?  If so, I think it would still be easier to have a routine Insert the "base" version as a Block, scale that, Explode it and define it as a new Block name with scale indication, than it would be to have a routine draw all the pieces every time.

Kent Cooper, AIA
Message 9 of 13
aliff_ahtenk
in reply to: j.palmeL29YX

Bro i am sorry i have been rude to you early.. but i am not in the mood that day..

But after thinking several ways, i think to use insert command in lisp.

Thank for your code, i am very greatful today. I will try it later.

 

This is what i found but dont know how to select the size.

I found that insert function already have the rotation if not skipped.

 

(defun c:fd ()
(setq insertpt1 (getpoint "\nSelect Flexible Dropper Point: "))
(command "_insert" "FD100" insertpt1 "" "")
(princ)
)

 

Code not try yet..

 

I would like to call these block name:

if user insert 100 it will insert block "FD100"

if user insert 150 it will insert block "FD150"

if user insert 200 it will insert block "FD200"

if user insert 250 it will insert block "FD250"

if user insert 300 it will insert block "FD300"

if user insert 350 it will insert block "FD350"

if user insert other value it will ask again to insert the size.

 

Thanks all for helping me on this lisp..

 

Message 10 of 13
aliff_ahtenk
in reply to: j.palmeL29YX

Bro i already finish the point, but it does not work on the scale..

 

this is the finish lisp:

 

(defun c:dfd (/)
(setq P0 (getpoint "\nSelect Flexible Dropper Point: "))
(setq SF (getdist "\nInsert Size: "))
(setq RA (getreal "\nDirection to Connect: "))
(setq ss (ssadd)) ; create selection set

(command "_arc" "_C" '(311.48 0) '(98.92 50) '(98.92 -50)) ; 1st arc
(ssadd (entlast) ss) ; add to selection set
(command "_arc" "_C" '(227.58 0) '(87.35 56.68) '(87.35 -56.68)) ; 2nd arc
(ssadd (entlast) ss) ; add to selection set
(command "_arc" "_C" '(155.01 0) '(70.55 49.98) '(70.55 -49.98)) ; 3rd arc
(ssadd (entlast) ss) ; add to selection set
(command "_arc" "_C" '(123.34 0) '(61.24 55.36) '(61.24 -55.36)) ; 4th arc
(ssadd (entlast) ss) ; add to selection set
(command "_arc" "_C" '(85.72 0) '(48.37 51.92) '(48.37 -51.92)) ; 5th arc
(ssadd (entlast) ss) ; add to selection set
(command "_arc" "_C" '(65.96 0) '(37.45 54.89) '(37.45 -54.98)) ; 6th arc
(ssadd (entlast) ss) ; add to selection set
(command "_arc" "_C" '(40.25 0) '(23.8 50.74) '(23.8 -50.74)) ; 7th arc
(ssadd (entlast) ss) ; add to selection set
(command "_arc" "_C" '(30.45 0) '(14.48 54.88) '(14.48 -54.88)) ; 8th arc
(ssadd (entlast) ss) ; add to selection set
(command "_arc" "_C" '(13.11 0) '(-0.41 51.55) '(-0.41 -51.55)) ; 9th arc
(ssadd (entlast) ss) ; add to selection set
(command "_arc" "_C" '(0 0) '(-9.34 52.72) '(-9.34 -52.72)) ; 10th arc
(ssadd (entlast) ss) ; add to selection set
;;; ... repeat for all arc's

(command "_line" '(98.92 50) '(87.35 56.68) "") ; 1st up line
(ssadd (entlast) ss)
(command "_line" '(98.92 -50) '(87.35 -56.68) "") ; 1st down line
(ssadd (entlast) ss)
(command "_line" '(87.35 56.68) '(70.55 49.98) "") ; 2nd up line
(ssadd (entlast) ss)
(command "_line" '(87.35 -56.68) '(70.55 -49.98) "") ; 2nd down line
(ssadd (entlast) ss)
(command "_line" '(70.55 49.98) '(61.24 55.36) "") ; 3rd up line
(ssadd (entlast) ss)
(command "_line" '(70.55 -49.98) '(61.24 -55.36) "") ; 3rd down line
(ssadd (entlast) ss)
(command "_line" '(61.24 55.36) '(48.37 51.92) "") ; 4th up line
(ssadd (entlast) ss)
(command "_line" '(61.24 -55.36) '(48.37 -51.92) "") ; 4th down line
(ssadd (entlast) ss)
(command "_line" '(48.37 51.92) '(37.45 54.89) "") ; 5th up line
(ssadd (entlast) ss)
(command "_line" '(48.37 -51.92) '(37.45 -54.89) "") ; 5th down line
(ssadd (entlast) ss)
(command "_line" '(37.45 54.89) '(23.8 50.74) "") ; 6th up line
(ssadd (entlast) ss)
(command "_line" '(37.45 -54.89) '(23.8 -50.74) "") ; 6th down line
(ssadd (entlast) ss)
(command "_line" '(23.8 50.74) '(14.48 54.88) "") ; 7th up line
(ssadd (entlast) ss)
(command "_line" '(23.8 -50.74) '(14.48 -54.88) "") ; 7th down line
(ssadd (entlast) ss)
(command "_line" '(14.48 54.88) '(-0.41 51.55) "") ; 8th up line
(ssadd (entlast) ss)
(command "_line" '(14.48 -54.88) '(-0.41 -51.55) "") ; 8th down line
(ssadd (entlast) ss)
(command "_line" '(-0.41 51.55) '(-9.34 52.72) "") ; 9th up line
(ssadd (entlast) ss)
(command "_line" '(-0.41 -51.55) '(-9.34 -52.72) "") ; 9th down line
(ssadd (entlast) ss)
;;; ... repeat for all lines
;; if complete geometry is drawn, modify it (move, scale, rotate)
(command "_move" ss "" '(0 0) P0)
(command "_scale" ss "" p0 sf)
(command "rotate" ss "" p0 ra)
(princ)
)

;; HTH for a beginning

Message 11 of 13
j.palmeL29YX
in reply to: aliff_ahtenk


@aliff_ahtenk wrote:

...  it does not work on the scale..

 


 

While the lisp is running the OSNAP must not be ON.

Either you disable it manually (F3) (and do never forgot it before each starting the LISP) or you add a line in the code to set the system variable OSNAPCOORD to 1. (I guess you have it set to 2).

The scaling works well for me. >>video<<

 

The next steps will be (a rough draft):

The moving, scaling and rotating should be removed in the code above. We will do it later (while inserting the block).

 

- Create a block name string using (strcat (FD (rtos sf))

- Test if this block name already exists.  If yes, erase the selection set ss and skip the next step.

- create a new block definition

  * Basepoint: will be P0

  * objects: will be the selection set ss

  * Blockname: use the name defined above
- insert the block at P0.

 

Try it.

 

 

BTW: This strategy is not very well, because with each using of this lisp will first drawn exactly the same objects. @Kent1Cooper's hints above pointed in a better direction.

 

 

 

 

 

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 12 of 13
j.palmeL29YX
in reply to: j.palmeL29YX

A necessary correction (sorry for the mistake):

For creating the new blockname use

(strcat "FD" (rtos sf))

 

 

My suggestion above (strcat (FD (rtos sf)) is wrong (typing error in the hurry).

My apologies.

 

 

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 13 of 13
j.palmeL29YX
in reply to: j.palmeL29YX

Here a suggestion how that can be done:

 

 

(defun c:test (/ P0 SF RA ss bl_name P_ep P_sp P_cp)
  (input)
  (Exist)
  (Insert_block)
  (princ)
)

(defun input (/)  ; ask for input values 
  (setq P0 (getpoint "\nWhere to insert: "))
  (setq SF (getdist "\nScale factor: "))
  (setq RA (getreal "\nRotation angle: "))
)

(defun exist (/)
  (setq bl_name (strcat "FD" (rtos sf))) ; generate Blockname 
  (If (not (tblsearch "block" bl_name))  ; If Blockname NOT yet exists 
; do the following:
    (progn
      (initialize) ; set lists of coordinates for lines and arcs
      (draw)   ; draw the initial geometry
      (command "block" bl_name "0,0" ss "") ; create a new block definition
    )
; If blockname already exists do nothing of that
  )
)


(defun initialize (/)
  (setvar "osnapcoord" 1) ; ignore running OSNAPs
  (setq ss (ssadd)) ; create new selection set
;| the following coordinates were grabbed from your drawing

  (setq	P_ep '((32.6826 184.524 0.0)  ; Endpoints of the arcs
               (1.44315 180.413 0.0)
	       (-50.6704 192.072 0.0)
	       (-84.4138 178.499 0.0)
	       (-131.069 192.099 0.0)
	       (-169.298 181.733 0.0)
	       (-214.355 193.749 0.0)
	       (-246.934 174.939 0.0)
	       (-305.723 198.38 0.0)
	       (-346.218 175.0 0.0)
	      )
  )
  (setq	P_sp '((32.6826 -184.524 0.0)    ; Startpoints of the arcs
	       (1.44315 -180.413 0.0)
	       (-50.6704 -192.072 0.0)
	       (-83.3013 -177.049 0.0)
	       (-131.069 -192.099 0.0)
	       (-169.298 -181.733 0.0)
	       (-214.355 -193.749 0.0)
	       (-246.934 -174.939 0.0)
	       (-305.723 -198.38 0.0)
	       (-346.218 -175.0 0.0)
	      )
  )
  (setq	P_cp '((0.0 0.0 0.0)   ; Centerpoints of the arcs
	       (-45.8702 4.6247e-10 0.0)
	       (-106.56 1.07436e-09 0.0)
	       (-140.876 0.546476 0.0)
	       (-230.844 2.3274e-09 0.0)
	       (-300.022 3.02486e-09 0.0)
	       (-431.674 4.3522e-09 0.0)
	       (-542.545 5.47001e-09 0.0)
	       (-796.52 8.03063e-09 0.0)
	       (-1090.16 1.09912e-08 0.0)
	      )
  )
)

(defun draw (/)
  (setq n 0)
  (repeat 10
    (command "_line" (nth n P_ep) (nth (+ n 1) P_ep) "") ; draw the upper lines
    (ssadd (entlast) ss)
    (setq n (+ n 1))
  )
  (setq n 0)
  (repeat 10
    (command "_line" (nth n P_sp) (nth (+ n 1) P_sp) "") ; draw the lower lines
    (ssadd (entlast) ss)
    (setq n (+ n 1))
  )
  (setq n 0)
  (repeat 10
    (command "_arc" "_C" (nth n P_cp) (nth n P_sp) (nth n P_ep))  ; draw the arcs
    (ssadd (entlast) ss)
    (setq n (+ n 1))
  )
)

(defun insert_block (/)
  (command "insert" bl_name P0 SF "" RA)  ; no comment needed ;-)
)

(princ)

 

HTH

 

 

 

 

 

 

 

Please mark "Accept as Solution" if my reply resolves the issue or answers your question, to help others in the community.

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

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

Post to forums  

State of Sustainability Webinar


AutoCAD Inside the Factory