Jump to content

Draw relative to an object (example arrow in a rectangle)


itacad

Recommended Posts

Hello, I was looking for a lisp to quickly draw an arrow...I found one but it asks too much information before starting ...

To give an example I really like how to draw an arrow in the windows Paint program, where it is sufficient to indicate two vertices of a rectangle and the arrow drawn is proportional to the rectangle.

I therefore thought to ask you this question: Is it possible to draw a polyline using relative points of an object? the relative points would be the object snap of a rectangle.

In the example file that I enclose, I can draw a polyline inside a rectangle using its relative points, I would like to do it automatically.

Greetings

ARROW IN THE RECTANGLE.dwg

Link to comment
Share on other sites

Using BIGAL's idea .. this should work:

(defun c:foo (/ a b c)
  ;; RJP » 2018-10-09
  (cond	((and ;; Duh :)
	      (setq a (getpoint "\nSpecify first corner point: "))
	      ;; Duh :)
	      (setq b (getcorner a "\nSpecify other corner point: "))
	      ;; Get width and height ( subtract x's & y's )
	      (setq c (mapcar 'abs (mapcar '- a b)))
	 )
	 ;; If the block arrow definition does not exist in drawing make it ( look into entmake )
	 (cond ((null (tblobjname "block" "PaintArrow"))
		(entmake '((0 . "BLOCK")
			   (100 . "AcDbEntity")
			   (67 . 0)
			   (8 . "0")
			   (100 . "AcDbBlockReference")
			   (2 . "PaintArrow")
			   (10 0 0 0)
			   (70 . 0)
			  )
		)
		(entmake '((0 . "LWPOLYLINE")
			   (100 . "AcDbEntity")
			   (67 . 0)
			   (8 . "0")
			   (100 . "AcDbPolyline")
			   (90 . 9)
			   (70 . 1)
			   (43 . 0)
			   (38 . 0)
			   (39 . 0)
			   (10 1 0)
			   (10 0 -0.5)
			   (10 0 -0.25)
			   (10 -1 -0.25)
			   (10 -1 0.25)
			   (10 0 0.25)
			   (10 0 0.5)
			   (10 1 0)
			   (10 0 0.5)
			  )
		)
		(entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
	       )
	 )
	 ;; Insert the block
	 (entmakex (list '(0 . "INSERT")
			 '(100 . "AcDbEntity")
			 '(8 . "PaintArrow")
			 '(100 . "AcDbBlockReference")
			 '(2 . "PaintArrow")
			 ;; Mid point between point 'a' & 'b' ( insertion point of block )
			 (cons 10 (polar a (angle a b) (/ (distance a b) 2.)))
			 ;; X scale / 2.
			 (cons 41 (/ (car c) 2.))
			 ;; Y scale
			 (cons 42 (cadr c))
			 '(43 . 1.0)
			 '(50 . 0.0)
		   )
	 )
	)
  )
  (princ)
)

 

Edited by ronjonp
* added arrow direction from pick points, added some comments
Link to comment
Share on other sites

... wow! ...just what I wanted!

please you could insert lines of comment and a little explanations? I don't understand how the lisp works and I'd like to try to prepare more drawings besides the arrow and more arrows.

Finally a suggestion, a request, a whim ...since it is an arrow, would it be possible to make four variations and decide the orientation of the arrow by using the arrow key or the arrow on the numeric keypad?

thank you

Link to comment
Share on other sites

A simple radio button dcl would be a good idea with 4 buttons. Just need some time. Grr ?

 

Re code above Google DXF codes or in the help dxf codes, as few quick ones 8 = layer, 2 =block name, 0 = object type,  10 is a point like start point, 11 is end point etc.

Edited by BIGAL
Link to comment
Share on other sites

17 hours ago, itacad said:

... wow! ...just what I wanted!

please you could insert lines of comment and a little explanations? I don't understand how the lisp works and I'd like to try to prepare more drawings besides the arrow and more arrows.

Finally a suggestion, a request, a whim ...since it is an arrow, would it be possible to make four variations and decide the orientation of the arrow by using the arrow key or the arrow on the numeric keypad?

thank you

I added some comments to the code above. Sorry don't have time to add options.

Link to comment
Share on other sites

  • 2 weeks later...

Hello! I modified the lisp slightly so that I have one for each direction of the arrow, but I have this question:

1) is it possible to draw the arrow on the layer 0? (I did not have time to try to see which line was to be modified for this)

2) is it possible to explode the arrow with the lisp after it has been drawn?

3) with the lisp in vertical direction, proportions respect to the source rectangle are not respected, how to correct to solve this problem?

4) would it be possible to make a single lisp that has the arrow direction as an input using the arrow keys or number keys 2 4 6 8?

regards

arrow.zip

Link to comment
Share on other sites

With regards to explode  it. Would make sense just draw a pline dont make it a block. You can still rotate the pline around some known point.

 

Can you clarify need it as a block or as a pline ? 

Link to comment
Share on other sites

(defun c:foo (/ a b c d)
  ;; RJP » 2018-10-09
  (cond	((and ;; Duh :)
	      (setq a (getpoint "\nSpecify first corner point: "))
	      ;; Duh :)
	      (setq b (getcorner a "\nSpecify other corner point: "))
	      ;; Get width and height ( subtract x's & y's )
	      (setq c (mapcar 'abs (mapcar '- a b)))
	 )
	 ;; If the block arrow definition does not exist in drawing make it ( look into entmake )
	 (cond ((null (tblobjname "block" "PaintArrow"))
		(entmake '((0 . "BLOCK")
			   (100 . "AcDbEntity")
			   (67 . 0)
			   (8 . "0")
			   (100 . "AcDbBlockReference")
			   (2 . "PaintArrow")
			   (10 0 0 0)
			   (70 . 0)
			  )
		)
		(entmake '((0 . "LWPOLYLINE")
			   (100 . "AcDbEntity")
			   (67 . 0)
			   (8 . "0")
			   (100 . "AcDbPolyline")
			   (90 . 9)
			   (70 . 1)
			   (43 . 0)
			   (38 . 0)
			   (39 . 0)
			   (10 1 0)
			   (10 0 -0.5)
			   (10 0 -0.25)
			   (10 -1 -0.25)
			   (10 -1 0.25)
			   (10 0 0.25)
			   (10 0 0.5)
			   (10 1 0)
			   (10 0 0.5)
			  )
		)
		(entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
	       )
	 )
	 ;; Insert the block
	 (cond ((setq d	(entmakex (list	'(0 . "INSERT")
					'(100 . "AcDbEntity")
					;; Here is the layer it gets inserted on
					;; but since you explode it does not matter
					'(8 . "PaintArrow")
					'(100 . "AcDbBlockReference")
					'(2 . "PaintArrow")
					;; Mid point between point 'a' & 'b' ( insertion point of block )
					(cons 10 (polar a (angle a b) (/ (distance a b) 2.)))
					;; X scale / 2.
					(cons 41 (/ (car c) 2.))
					;; Y scale
					(cons 42 (cadr c))
					'(43 . 1.0)
					'(50 . 0.0)
				  )
			)
		)
		(setq d (vlax-ename->vla-object d))
		(while (getpoint "\nPick point to flip rotation: ")
		  (vla-put-rotation d (+ (/ pi 2.) (vla-get-rotation d)))
		  (vla-update d)
		)
		;; Why explode ?
		(vla-explode d)
		(vla-delete d)
	       )
	 )
	)
  )
  (princ)
)

 

Edited by ronjonp
Link to comment
Share on other sites

Hello, thank you very much...Nice way to direct the arrow!!!

The explanation for the explode is that if I copy drawing pieces from one file to another where the paintarrow block is already defined, it is resized...it would be enough for me to have exploded the block, but not the polyline that forms the block as in the last version.

For the layer question, which lines must be corrected for draw the polyline on the layer 0 (my problem is that the block and the layer have the same name "Paintarrow" so I have to do a lot of combination to find out how to make the correction.

Greetings and thanks again

 

 

 

 

Link to comment
Share on other sites

17 hours ago, itacad said:

Hello, thank you very much...Nice way to direct the arrow!!!

The explanation for the explode is that if I copy drawing pieces from one file to another where the paintarrow block is already defined, it is resized...it would be enough for me to have exploded the block, but not the polyline that forms the block as in the last version.

For the layer question, which lines must be corrected for draw the polyline on the layer 0 (my problem is that the block and the layer have the same name "Paintarrow" so I have to do a lot of combination to find out how to make the correction.

Greetings and thanks again

 

 

 

 

I cannot replicate the resizing of the block when pasting into a drawing? Also, look at the comments in the code above .. it gives you direction on the layering.

2018-10-24_8-14-36.gif

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