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

need some lisp code fix

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
745 Views, 8 Replies

need some lisp code fix

Hello, I'm writting this code, and I don't know why sometimes offseting line from my drew polyline, sometimes from last newest line. Also can you tell me how control in which side it should be offseting.

 

 

Edited by
Discussion_Admin

 

8 REPLIES 8
Message 2 of 9
pbejse
in reply to: Anonymous


@Anonymous wrote:

Hello, I'm writting this code, and I don't know why sometimes offseting line from my drew polyline, sometimes from last newest line. .


offset_taskas is what dictates where the "new line" will appear since the polar distance remains constant througout the program, when the offset distance surpass the value of the polar distance then it will look as if the "drew polyline" line were the one being offset. in reality instead of going towards the original direction it went to the opposite side as variable offset_taskas is behind the "new" line.

 


@Anonymous wrote:

Also can you tell me how control in which side it should be offseting.


Depending on how the polyline is created [direction wise] clockwise or counter clockwise. again these lines will be a factor to the "side" to offset

 

 (setq kampas (- (angle t1 t2) (/ pi 2)))
 (setq offset_taskas (polar t1 kampas 1))

 

BTW: targetting specific index number is never  a good idea

 

(setq t1 (nth 14 linijosduomenys))

(setq t2 (nth 18 linijosduomenys))

 

Depending on the enitity properties 14 may not be the first DXF 10 of the selected pline and it goes for the rest of the index number.

 

If i could only see what the final result is then i can give you a workable solution or modify your code to work as intended.

 

HTH

 

 

 

Message 3 of 9
pbejse
in reply to: pbejse

oops i made a boo-boo thinking your offsetting the "newly" created line, At any rate, i have a question for you.

Are the prompted distance the offset value from the selected pline? so if 1.0 2.23 and 3.8 is entered, last line would be 3.8 away from the orignal line and not total of the 3 values which is 7.03?

 

Another thing, i assume all polylines are straight segments. otherwise the total length would not give you an acurate length at the end of the routine.

 

 

Message 4 of 9
Anonymous
in reply to: pbejse

some times last line is 7,03 from original line, some times 3,8 from original line, and I can't control it
also I can't control in whick side of original line it offseting
Message 5 of 9
pbejse
in reply to: Anonymous


@Anonymous wrote:
some times last line is 7,03 from original line, some times 3,8 from original line, and I can't control it
also I can't control in whick side of original line it offseting

So which one is the correct offset value for the last item? 3.8 or 7.03?

 

As for the side to offset, would it be okay with you if your prompted for direction?

 

Tell you waht post an image or dwg file that shows the intended result and  enumerating the input values

 

 

Message 6 of 9
Anonymous
in reply to: pbejse

this is corrent version, 11 12 15 from original line, but simetimes it be 11 (11+12=)23 (11+12+15=)38

 

and it offseting in top of original line, but I need to control to offesting side (top or bottom)

Message 7 of 9
pbejse
in reply to: Anonymous


@Anonymous wrote:

this is corrent version, 11 12 15 from original line, but simetimes it be 11 (11+12=)23 (11+12+15=)38

 

and it offseting in top of original line, but I need to control to offesting side (top or bottom)


Vanilla: Try this and we'll pick from this if we need to add more conditions.

 

(defun C:trasa (/ tasku_sarasas	 pasirinkti	linijos_nuoroda
		  data		 atstumas	mode
		  SideToOffset	 colors		ltype
		  OffsetValuesAndSome
		 )
	  (setq data (list
		 '(1 3 (140 26 10) ("V1" "F1" "E1"))
		 '(2 4 (140 26 30 10)
		   ("V1" "F1" "D1" "E1")
		  )
		 '(3 6 (140 26 30 190 40 10)
		   ("V1" "F1" "D1" "T1" "R1" "E1")
		  )
	       )
	)
	(setq atstumas '("pirmas"      "antras"	     "trecias"
			 "ketvirtas"   "penktas"     "sestas"
			)
	)  
(if
	  (and
	       (setq tasku_sarasas nil  ;; Can be removed: for test purposes only
		     pasirinkti	nil 	;; Can be removed: for test purposes only
		     linijos_nuoroda
		      (car (entsel "nurodykite polilinija:"))
	       )
	      (setq linijosduomenys (entget linijos_nuoroda))
	      (eq (cdr (assoc 0  linijosduomenys)) "LWPOLYLINE")
	       )
  	(progn
		 (foreach ten linijosduomenys
		   (if (= (car ten) 10)
		     (setq tasku_sarasas
			    (append tasku_sarasas
				    (list (cdr ten))
			    )
		     )
		   )
		 )
		(while (not (< 0 pasirinkti 4))
		  (setq	pasirinkti
			 (getint "1 - minimalus, 2 - vidutinis, 3 - maksimalus:")
		  )
		)
		(setq mode (assoc pasirinkti data))
		(setq colors (caddr mode)
		      Ltype  (last mode)
		)
		 (setq OffsetValuesAndSome
			 (mapcar (function (lambda (a b c)
				(initget 7)
				(setq ov (getreal (strcat "\n" c " atstumas?: ")))
				(list ov a b)))
			  	    colors Ltype atstumas))

  		(setq SideToOffset (getpoint "\nSide To offset: "))
		  (foreach item OffsetValuesAndSome
		   (command "_.Offset" (car item) linijos_nuoroda "_non"
			     SideToOffset "")
		    (command "_.chprop" (entlast) ""
			     "Color" (cadr item)
			     "lw" "0.5" "ltype" (last item) ""
		    )
		    )
	  (print
  		(apply '+ (mapcar 'distance
		  tasku_sarasas (cdr tasku_sarasas))
  		)
	     )
	  )
  (princ "\nInvalid Selection")
  )
  (princ)
  )

 

Later you may need to add a test for valid linetypes

 

 

Message 8 of 9
Anonymous
in reply to: pbejse

I think it's work.
Thank You ;]
Message 9 of 9
pbejse
in reply to: Anonymous


@Anonymous wrote:
I think it's work.
Thank You ;]

Good for you, and i think you can pick from where i left-off.

The code could be improved but  since your are the author, i did not deviate too much from your orignal coding.

 

Cheers.

 

BTW: Welcome to the forum Smiley Happy

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

Post to forums  

Autodesk Design & Make Report

”Boost