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

need help on this drawing lisp (layers and dimension line ucs)

13 REPLIES 13
Reply
Message 1 of 14
miroslav.pristov
868 Views, 13 Replies

need help on this drawing lisp (layers and dimension line ucs)

hello all this is a lisp i wrote

 

(defun C:TP1()
(setq tac1 (getpoint "\n First point A "))
(setq tac2 (getpoint "\n Second point B "))
(setq a (getreal "\n Insert dimension a: "))
(setq b (getreal "\n Insert dimension b: "))
(setq c (getreal "\n Insert dimension c: "))
(setq d (getreal "\n Insert dimension d: "))
(setq rast (distance tac1 tac2))
(command "ucs" "3" tac1 tac2 "")
(setq t1 (list (- c) a 0))
(setq t2 (list (+ rast c) a 0))
(setq t3 (list (+ rast c) (- b) 0))
(setq t4 (list (- c) (- b) 0))
(setq t5 (list (- c) (- a d) 0))
(setq t6 (list (+ rast c) (- a d) 0))
(setq t7 (list 0 0 0))
(setq t8 (list rast 0 0))
(setq t9 (list (+ rast c) (+ 150 a) 0))
(setq t10 (list (- c) 0 0))
(setq t11 (list (/ rast 1.2) 0 0))
(setq t12 (list (+ rast c) (+ 100 a) 0))
(setq t13 (list 0 (+ 100 a) 0))
(setq t14 (list (+ rast c) 0 0))
(command "osnap" "none")
(command "pline" t1 t2 t3 t4 t1 "")
(command "_dimlinear" t1 t2 t9)
(command "_dimlinear" t1 t7 t13)
(command "_dimlinear" t8 t14 t12)
(command "_dimlinear" t4 t10 t11)
(command "_dimlinear" t10 t1 t11)
(command "line" t5 t6 "")
(command "line" t7 t8 "")
(command "osnap" "END,MID,INT,EXT,APP,CEN,NOD,QUA,INS,PER,TAN,NEA,PAR" "")
(command "ucs" "w")

)

 

I need help because i have a problem with dimension lines text which varies depending on the mode of entry points A and B. On picture bellow i have 4 ways of entry A and B points with dimension lines in white that is correct, dimension lines in purple that is incorrect (the text is upside down). I need that incorrect dimension lines should be like yellow dimension lines on picture. Also if i draw all of this in current layer i need help to make (command "line" t5 t6 "") to be draw in layer 2, and (command "line" t7 t8 "") to be draw in layer 3. after all is finish i need current layer from the start to be activate again.

 

help.png

 

Thank you very much for help and any other corrections in improving  this lisp is welcome ๐Ÿ™‚

13 REPLIES 13
Message 2 of 14

i find the solution for layers, the dimension lines are still the problem

Message 3 of 14
scot-65
in reply to: miroslav.pristov

Perhaps include a check as to which quadrant
(angle tac1 tac2) is in and do a bubble sort?

(setq tac3 tac1 tac1 tac2 tac2 tac3 tac3 nil)

Also...
(if (< (getvar 'OSMODE) 16384)
(setvar 'OSMODE (+ 16384 (getvar 'OSMODE)))
);if
and
(if (>= (getvar 'OSMODE) 16384)
(setvar 'OSMODE (- 16384 (getvar 'OSMODE)))
);if

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 4 of 14
miroslav.pristov
in reply to: scot-65

thank you for your answer but i dont know how to write that and exactly where to put it in the command. I m new in this and i dont understand what you wrote honestly. but i need help.

Message 5 of 14
miroslav.pristov
in reply to: scot-65

can you help me with this problem please. with orientation of dimension line text
Message 6 of 14

ok i will now attach dwg example and lisp file. The text in lisp file is not in english but i put order for input data in example file. thank you for your help

 

P.S. i know maybe the lisp can be wrote better but thats the only way i know, for now

Message 7 of 14
scot-65
in reply to: miroslav.pristov

Apologies as I did not see your image very good the first time around.

You are setting the UCS to the angle of the 2 selected points.
I believe the dimensions you highlighted are upside down?
If so, first set the UCS to draw your lines:
(command "ucs" "3" tac1 tac2 "")

Just before dimensioning, reset the UCS in the other direction
based on the quadrant (angle) of the 2 selected points:
(command "ucs" "3" tac2 tac1 "")

It looks like you determined the dimension line locations (t9).

I suspect you might require TRANS as I have not tested your work.
If the dimensions do not behave, you will have to use TRANS or
not use UCS at all. Use POLAR instead.

I personally learned by trial and error and by following examples.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 8 of 14

My guess is that if you want the Dimension text in the more readable direction, you're going to need to do the Dimensions in the WCS [or at least that will be easier than other ways it might be done].  Probably scot-65's suggestion that (trans) functions will be needed is correct.  I would suggest something like this [untested]:

 

(defun C:TP1()

  (setq tac1 (getpoint "\n First point A "))
  (setq tac2 (getpoint "\n Second point B "))
  (setq a (getreal "\n Insert dimension a: "))
  (setq b (getreal "\n Insert dimension b: "))
  (setq c (getreal "\n Insert dimension c: "))
  (setq d (getreal "\n Insert dimension d: "))
  (setq rast (distance tac1 tac2))
  (command "line" tac1 tac2 ""); before changing UCS, instead of with t7 & t8 later, but could keep it later
  (command "ucs" "3" tac1 tac2 "")
  (setq t1 (list (- c) a 0))
  (setq t2 (list (+ rast c) a 0))
  (setq t3 (list (+ rast c) (- b) 0))
  (setq t4 (list (- c) (- b) 0))
  (setq t5 (list (- c) (- a d) 0))
  (setq t6 (list (+ rast c) (- a d) 0))
  (setq t7 (list 0 0 0))
  (setq t8 (list rast 0 0))
  (setq t9 (list (+ rast c) (+ 150 a) 0))
  (setq t10 (list (- c) 0 0))
  (setq t11 (list (/ rast 1.2) 0 0))
  (setq t12 (list (+ rast c) (+ 100 a) 0))
  (setq t13 (list 0 (+ 100 a) 0))
  (setq t14 (list (+ rast c) 0 0))
  (command "osnap" "none")
  (command "pline" t1 t2 t3 t4 t1 "")

  (command "line" t5 t6 ""); earlier than before, so (trans) will not be needed

  (foreach pt '(t1 t2 t7 t8 t9 t10 t11 t12 t13 t14); added: convert only those used in Dimensions...

    (set pt (trans (eval pt) 1 0)); from current UCS terms to WCS terms

  ); foreach

  (command "ucs" "w"); before making Dimensions, so Dimension text will be more upright

  (command "_dimaligned" t1 t2 t9); aligned Dimensions instead of linear
  (command "_dimaligned" t1 t7 t13)
  (command "_dimaligned" t8 t14 t12)
  (command "_dimaligned" t4 t10 t11)
  (command "_dimaligned" t10 t1 t11)
  (command "osnap" "END,MID,INT,EXT,APP,CEN,NOD,QUA,INS,PER,TAN,NEA,PAR" "")
)

Kent Cooper, AIA
Message 9 of 14

i made some modifications added or change points (bolded and underlined ones) and now its work perfect. Thank you very much

 

(defun C:TP1()

  (setq tac1 (getpoint "\n First point A "))
  (setq tac2 (getpoint "\n Second point B "))
  (setq a (getreal "\n Insert dimension a: "))
  (setq b (getreal "\n Insert dimension b: "))
  (setq c (getreal "\n Insert dimension c: "))
  (setq d (getreal "\n Insert dimension d: "))
  (setq rast (distance tac1 tac2))
  (command "line" tac1 tac2 ""); before changing UCS, instead of with t7 & t8 later, but could keep it later
  (command "ucs" "3" tac1 tac2 "")
  (setq t1 (list (- c) a 0))
  (setq t2 (list (+ rast c) a 0))
  (setq t3 (list (+ rast c) (- b) 0))
  (setq t4 (list (- c) (- b) 0))
  (setq t5 (list (- c) (- a d) 0))
  (setq t6 (list (+ rast c) (- a d) 0))
  (setq t7 (list 0 0 0))
  (setq t8 (list rast 0 0))
  (setq t9 (list (+ rast c) (+ 150 a) 0))
  (setq t10 (list (- c) 0 0))
  (setq t11 (list (/ rast 1.2) 0 0))
  (setq t12 (list (+ rast c) (+ 100 a) 0))
  (setq t13 (list 0 (+ 100 a) 0))
  (setq t14 (list (+ rast c) 0 0))
  (command "osnap" "none")
  (command "pline" t1 t2 t3 t4 t1 "")

  (command "line" t5 t6 ""); earlier than before, so (trans) will not be needed

  (foreach pt '(t1 t2 t4 t7 t8 t9 t10 t11 t12 t13 t14); added: convert only those used in Dimensions...

    (set pt (trans (eval pt) 1 0)); from current UCS terms to WCS terms

  ); foreach

  (command "ucs" "w"); before making Dimensions, so Dimension text will be more upright

  (command "_dimaligned" t1 t2 t9); aligned Dimensions instead of linear
  (command "_dimaligned" t10 t7 t13)
  (command "_dimaligned" t8 t14 t12)
  (command "_dimaligned" t4 t10 t11) 
  (command "_dimaligned" t10 t1 t11)
  (command "osnap" "END,MID,INT,EXT,APP,CEN,NOD,QUA,INS,PER,TAN,NEA,PAR" "")
)

 

 

Message 10 of 14

can i ask you something more. I have 2 questions

 

1. how to change this line

 

(setq t9 (list (+ rast c) (+ 150 a) 0))

 

to have absolute value of "a". My input data is sometimes positive or negative number. if i put it 25 then the sum is 175, if i put -25 then the sum is 125. I always want it to be 175

 

2. want to add one more input line like this one existed

 

  (setq c (getreal "\n Insert dimension c: "))

 

to be like 

 

(setq c1 (getreal "\n Insert dimension c1: "))

(setq c2 (getreal "\n Insert dimension c2: "))

 

but for the second one, if it is exactly the same like the input for c1 not to type anything just to hit enter and then c2 will be like c1. need some modification in those second line

 

 

 

 

Message 11 of 14

Hi... you might try this modified code. I used very basic function (polar). It's simple and no need for messing with UCS just because it makes simplier calculation. Also, your routine should return same OSMODE as was before the routine started - even in case of error.

 

There is (abs) function for make your input always possitive.

 

Spoiler
(defun C:TP2 ( / *error* oOSMODE t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 )

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
      )
    (setvar 'OSMODE oOSMODE)
    (princ)
    )

  
  (setq oOSMODE (getvar 'OSMODE))

  (setq t7 (getpoint "\n First point A "))
  (setq t8 (getpoint "\n Second point B "))

  (setq a (abs (getreal "\n Insert dimension a: ")))
  (setq b (getreal "\n Insert dimension b: "))
  (setq c1 (getreal "\n Insert dimension c1: "))
  (setq c2 (cond ((getreal (strcat "\n Insert dimension c2 <" (rtos c1 2 0) ">: ")))
		 (c1)))
  (setq d (getreal "\n Insert dimension d: "))

  (setq ang (angle t7 t8)
	anp (+ ang (* pi 0.5)))
  (setq rast (distance t7 t8))
  
  (setq t10 	(polar t7 	ang 	(- c1))
	t1 	(polar t10 	anp 	a)
	t4	(polar t10	anp	(- b))
	t5	(polar t1	anp	(- d))

	t2	(polar t1 	ang 	(+ c1 rast c2))
	t3 	(polar t2 	anp 	(- (+ a b)))
	t6 	(polar t2 	anp 	(- d))
	t14 	(polar t8 	ang 	c2)
	t12	(polar t2 	anp	100)
	t9	(polar t2 	anp	150)

	t11	(polar t7 	ang 	(/ rast 1.2)))

  (setvar 'OSMODE 0)

  (command "_pline" t1 t2 t3 t4 t1 "")
  (command "_dimaligned" t1  t2  t9)
  (command "_dimaligned" t10 t7  t12)
  (command "_dimaligned" t8  t14 t12)
  (command "_dimaligned" t4  t10 t11)
  (command "_dimaligned" t10 t1  t11)
  (command "_line" t5 t6 "")
  (command "_line" t7 t8 "")

  (setvar 'OSMODE oOSMODE)
  (princ)
)
Message 12 of 14

you lisp work perfect

 

but you dont understand what i mean when i said i want absolute value. so this input abs for value a is not good, and everything further in lines related to that.

 

i ll explain better now using your modified lisp

 

if i input "a","b", and "d" as a positive values then the distance of aligned dimension lines from closer edge of object is 100 and 150 what i wanted in first time

 

but if i input "a","b", and "d" as a negative values then the distance of aligned dimension lines from farther edge of object is 100 and 150. and from closer is 100-a-b, 150-a-b. i always want that distance to be 100 and 150 from closer edge. 

 

 

so i think i need some modifications in lines 

 

t12 (polar t2 anp 100)
t9 (polar t2 anp 150)

 

to work only when a,b,d are positive, and if they are negative then values 100 from first line to be sum of 100+abs"a"+abs"b", and value 150 from second line to be sum of 150+abs"a"+abs"b"

 

I hope you understand. Thank you for your time

 

 

 

 

 

 

 

 

Message 13 of 14


@miroslav.pristov wrote:

.... 

1. how to change this line ... to have absolute value of "a". ....

 

2. .... 

(setq c1 (getreal "\n Insert dimension c1: "))

(setq c2 (getreal "\n Insert dimension c2: "))

 

but for the second one, if it is exactly the same like the input for c1 not to type anything just to hit enter and then c2 will be like c1. .... 


1. There is an absolute-value AutoLisp function:

 

(setq t9 (list (+ rast c) (+ 150 (abs a)) 0))

 

2.  Here is one way to do that:

(setq c1 (getreal "\n Insert dimension c1: "))

(setq c2

  (cond

    ((getreal "\n Insert dimension c2 <= c1>: "))

      ;; if User enters a value, it takes it; Enter returns nil, and it goes on to the next condition:

    (c1)

  ); cond

); setq

 

It can also be made to show the actual value of c1 instead of just <= c1>:

 

    ((getreal (strcat "\n Insert dimension c2 <" (rtos c1) ">: ")))

 

Read about the (rtos) function if you want to specify the mode and precision of the text string representing the c1 value.

Kent Cooper, AIA
Message 14 of 14


@miroslav.pristov wrote:

 

 

 

to work only when a,b,d are positive, and if they are negative then values 100 from first line to be sum of 100+abs"a"+abs"b", and value 150 from second line to be sum of 150+abs"a"+abs"b"

 

 


... I'm pretty sure you can figure out yourself. Use the (abs) function me and Kent shown you.

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report