Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

help please for automatic angular dimension lisp

Anonymous

help please for automatic angular dimension lisp

Anonymous
Not applicable

Hi 
can anyone help with a lisp that can create angular dimensions for a every bend in a line taking the smaller angle along the line like this 
please help I need it 

0 Likes
Reply
Accepted solutions (1)
2,349 Views
13 Replies
Replies (13)

devitg
Advisor
Advisor

@Anonymous Please upload the sample dwg.  to replicatye your own dim style 

0 Likes

Anonymous
Not applicable

The standard dimension style or create one anything will be fine and I can change/modify it after  executing the command 
Thank you for your help 

0 Likes

Kent1Cooper
Consultant
Consultant

You have two colors of "lines" -- do I assume correctly from the wording "every bend in a line" that you really mean every change in direction in a Polyline, and that the segments in question would be adjacent parts of one object, and not different colors?  Or do the different colors indicate that you mean to apply this to adjacent but independent Line objects?

Kent Cooper, AIA
0 Likes

devitg
Advisor
Advisor

@Anonymous Just a simple sample.dwg will clear all @Kent1Cooper  doubts . 

 

0 Likes

Anonymous
Not applicable

Ohh sorry the colors was only to show that there is a bend and the three lines are the same but to show that i want the small angle, and yes  i meant every change in direction.
To make it clear the program will be that 

(Do a angular dimension on every change in direction in a polyline but taking the small angle like the first one in my pic the 2 deg )

And im sorry for not making things clear 

0 Likes

Anonymous
Not applicable

Here is  a drawing for a pipe line I did the angular dimensions manual one by one when there is a bend (change in direction) 
can you make lisp to make this process automatic. Note that the I'm taking the smaller angle of the bend 

0 Likes

hak_vz
Advisor
Advisor
Accepted solution

Here is my code to create direction angles. It probably won't work with your sample (duplicate points and some other stuff I don't have time to inspect), but on lwpolyline with line segments it produces correct result.

 

(defun c:adang 
	( / 
		 *error* adoc take pointlist2d p2-3 vector unit_vect create_value_vector mod_vect
		 vect_dot v*s v+ ss eo coords i a b c d osm LM:Unique
	)
	; hak_vz Tue Jul 6th, 2021
	
	(defun *error* ()
		(setvar 'cmdecho 1)
		(setvar 'osmode osm)
		(if (and adoc) (vla-endundomark adoc))
		(princ)
	)
	(defun LM:Unique ( l ) (if l (cons (car l) (LM:Unique (vl-remove (car l) (cdr l))))) )
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(defun pointlist2d (lst / ret) (while lst (setq	ret (cons (take 2 lst) ret) lst (cddr lst))) (reverse ret))
	(defun p2-3 (p) (append p (list 0)))
	(defun vector (p1 p2) (mapcar '- p2 p1))
	(defun unit_vect (v)(mapcar '* v (create_value_vector (length v) (/ 1 (mod_vect v)))))
	(defun create_value_vector (n val / r ) (repeat n (setq r (cons val r))) r)
	(defun mod_vect (v)(sqrt(vect_dot v v)))
	(defun vect_dot (v1 v2)(apply '+ (mapcar '* v1 v2)))
	(defun v*s (v s)(mapcar '* v (create_value_vector (length v) s)))
	(defun v+ (v1 v2)(mapcar '+ v1 v2))
	(setq adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(princ "\nSelect pipeline >")
	(setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
	(setq osm (getvar 'osmode))
	(setvar 'osmode 0)
	(setvar 'cmdecho 0)
	(vla-endundomark adoc)
	(vla-startundomark adoc)
	(cond 
		((and ss)
			(setq eo (vlax-ename->vla-object (ssname ss 0)))
			(setq coords (LM:Unique (pointlist2d (vlax-get eo 'Coordinates))))
			(setq i 0)
			(while (< (setq i (+ i 1)) (- (length coords) 1)) 
				 (setq
					a (nth (- i 1) coords)
					b (nth i coords)
					c (nth (+ i 1) coords)
				)
				(setq a (mapcar '* (mapcar '+ a b) '(0.5 0.5)))
				(setq c (mapcar '* (mapcar '+ b c) '(0.5 0.5)))
				(setq d (v+ b (v*s (unit_vect (vector a b)) (* 0.5 (distance b c)))))
				(setq d (mapcar '* (mapcar '+ c d) '(0.5 0.5)))
				(command "_.dimangular"  c  a  d)
			)
		)
	)
	(vla-endundomark adoc)
	(setvar 'cmdecho 1)
	(setvar 'osmode osm)
	(princ)
)

 

Untitled.png

 

Miljenko Hatlak

EESignature

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.

Anonymous
Not applicable

Thank you very much it's amazing
I divided the project into smaller segments and run the command and it works pretty amazing but can we optimize it furthermore? I included a small segment, it missed like 4 angles(I did a circle on them) it's pretty good but can we make it to fully detect the angles?
Or tell me how to use it so it can detect every angle 
*The angular dim in the drawing done by the code *
Thank you very very much 

0 Likes

hak_vz
Advisor
Advisor

@AnonymousI have spent yesterday almost four hours creating this code. In essence this should be easy task to do but it has produced a lots of troubles in execution. To create angular dimension there are two options, one using command dimangular (used in code) or with entmake (complicated).

With command approach there are several options to create direction angle depending on pick order pf polyline segments . Sometime result can be smaller angle (direction) and sometime you can receive larger angle ie angle between two poly segments. I have included a little trick that should force only creation of direction angle, and if it works it works correctly. For some angles between segments order of selection would probably have to be reversed, and different math should be used.  Of course this code only works with line segments.

 

I would run code on whole length, without dividing. Before using adang command you should remove all zero length segments (command overkill) or explode end remove all lines with length less then 0.5, or equal to 0, and join back to polyline. Run the code and create angular dims where they are created wrong.   

Miljenko Hatlak

EESignature

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

pumar.manikanta
Community Visitor
Community Visitor

Thanks for the solution. but there is error occuring like "too many arguments" and not giving whole polyline angular dimensions

0 Likes

pumar.manikanta
Community Visitor
Community Visitor
please solve the error "too many arguments" not giving whole polyline angular dimensions
0 Likes

hak_vz
Advisor
Advisor

@pumar.manikanta 

 

Is your base object polyline?  When used as intended (read older posts) it works without error.

Attach sample drawing, but I don't have time to work on code and modify it according to each individual request.

 

For a test, create polyline with line segments (no arcs). Run command ADANG and pick this polyline. It should work as expected. It will not create dimension if segments are parallel. Check final result drawing and add missing one 

 

Miljenko Hatlak

EESignature

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

hiraram_prajapati
Participant
Participant
Hi,

this lisp not giving entire polyline angle, somewhere stopping...Please update and re-sent
0 Likes