Trouble with an offset lisp

Trouble with an offset lisp

Satoews
Advocate Advocate
433 Views
2 Replies
Message 1 of 3

Trouble with an offset lisp

Satoews
Advocate
Advocate

Having some trouble with some code previously made by BeeKeeCZ here .

 

The trouble I am having is that the offset command is really not liking the osp point in some instances, making me use the Changepoint to clear the osp variable. I have been trying to set up an using userdefined *error* but i don't think it is technically an error. System var errno keeps showing 0 right after I fail to put a line for offset. The only thing I see that even comes close to an error message is "Cannot offset that object." when trying to offset a AECC_PARCEL_SEGMENT in the conditions stated above. Any ideas? Thanks in advance!! 

 

P.S. I know the way I set up initget is a little wierd, but it was the only way i could get the program to work the way I wanted it to, if anyone can school me on how to set a cond that can shorten that up I would love that too. thanks!!

 

(defun c:oof ( / ensel dist done osp)

  (or esmtlist
      (setq esmtlist (ssadd)))
 

  (while (not done)

    (or dist
	(setq dist (cond
          ((getdist
             (strcat
               "\nEnter Distance to offset: [Enter to accept: <"
               (rtos (setq dist (getvar 'Offsetdist)) 2 2)
               ">: "
               )
             )
           )
          (dist)
          )))



	;;(getdist "\nSpecify distance of offset: ")))
    
    (setvar 'ERRNO 0)
    (initget "5 6 7 7.5 10 12 15 20 25 30 33 35 40 45 50 60 66 70 75 80 90 100 120 140 150 Distance Changepoint Boundary")
    (setq ensel (entsel (strcat "\nSelect object to offset, offset distance or <Distance> <Changepoint> Current offset distance <"(rtos dist)">: ")))  ;; hit enter to end
	
    (cond 
	  ((= ensel "5") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "6") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "7") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "7.5") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "10") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "12") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "15") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "20") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "25") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "30") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "33") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "35") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "40") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "45") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "50") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "60") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "66") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "70") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "75") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "80") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "90") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "100") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "120") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "140") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "150") ;; set distance
	  (setq dist (distof ensel)))
	  
	  ((= ensel "Distance") ;; set distance
	  (setq dist nil))
	  
	  ((= ensel "Changepoint") ;; set point
	  (setq osp nil))
	  
	  ((= ensel "Boundary") ;; boundary set
	  (c:boo))
	  
	  ((and (not ensel)	;; ended by enter
		(eq (getvar 'ERRNO) 52))
	   (setq done T))
	  
	  ((not ensel)) ;; missed
	 	  
	  ((not (wcmatch (cdr (assoc 0 (entget ( car ensel)))) "LINE,AECC_PARCEL_SEGMENT,LWPOLYLINE")))

	     ;; selected anything but AECC_PARCEL_SEGMENT,LINE,LWPOLYLINE
	  
	  (ensel 		;; correct selection
	   
	   (or osp
	       (setq osp (getpoint "\nSpecify point on side to offset multiple lines: ")))

	   (command)
	   (command "_.OFFSET" dist (car ensel) osp "")
	   ;;;;;; while "Cannot offset that object." I would like to keep reseting the osp till it finds one it like.;;;;;;	
	   (ssadd (entlast) esmtlist)
	  )
	)
  )
  (princ)
)

(defun c:boo(/)

  (command 
    "PEDIT" "M" esmtlist "" "J" "100" ""	
  )
)
Shawn T
0 Likes
434 Views
2 Replies
Replies (2)
Message 2 of 3

Satoews
Advocate
Advocate

of course after I set this up I had an idea to fix it. Instead of focusing on setting osp if it errored on offset its possible to make the point the offset uses better. this is what I had in mind.

 

	  (ensel 		;; correct selection
	   
	   (or osp
	       (setq osp (getpoint "\nSpecify point on side to offset multiple lines: ")))
		   
		   (setq pt1 osp)
           (setq pt2 (cadr ensel))
           (setq dst (distance pt1 pt2))
           (setq ang (angle pt1 pt2))
           (setq npt (polar pt1 ang (/ dst 1.75)))  

	   (command)
	   (command "_.OFFSET" dist (car ensel) NPT "")
	   (ssadd (entlast) esmtlist)
 
	  )
	)
  )

 

This moves the point offset is going to use in a much more agreeable postion. Testing at 1 am seemed to be much improved, but I will look at it the morning and get some sleep =P. 

 

 

Shawn T
0 Likes
Message 3 of 3

ВeekeeCZ
Consultant
Consultant

Hi, I suggest some improvements as well. (I did not found any problem with osp)

 

- no need for so many conditions for distance

- turn osnap off when offset prompt for point

- make user prompt with common format like

 

Hey, how are you? [Good/Bad] <why the f*ck you care!>: 

 

- and about the point... not sure if I follow you.. I guess you pick the side at the beginning and then it the same... 

 

Spoiler
(defun c:oof1 ( / ensel dist done osp)

  (or esmtlist
      (setq esmtlist (ssadd)))
 

  (while (not done)

    (or dist
	(setq dist (cond ((getdist (strcat "\nEnter Distance to offset <"
					   (rtos (setq dist (getvar 'Offsetdist)) 2 2)
					   ">: ")))
			 (dist))))

	;;(getdist "\nSpecify distance of offset: ")))
    
    (setvar 'ERRNO 0)
    (initget "5 6 7 7.5 10 12 15 20 25 30 33 35 40 45 50 60 66 70 75 80 90 100 120 140 150 Distance changePoint Boundary")
    (setq ensel (entsel (strcat "\nSelect object to offset with current distance: "(rtos dist)", or [Distance/changePoint/Boundary] or set new distance <exit>: ")))  ;; hit enter to end
	
    (cond
	  
	  ((= ensel "Distance") ;; set distance
	  (setq dist nil))
	  
	  ((= ensel "changePoint") ;; set point
	  (setq osp nil))
	  
	  ((= ensel "Boundary") ;; boundary set
	  (c:boo))

	  ((= (type ensel) 'STR) ;; set distance
	   (setq dist (distof ensel)))
	  
	  ((and (not ensel)	;; ended by enter
		(eq (getvar 'ERRNO) 52))
	   (setq done T))
	  
	  ((not ensel)) ;; missed
	 	  
	  ((not (wcmatch (cdr (assoc 0 (entget (car ensel)))) "LINE,AECC_PARCEL_SEGMENT,LWPOLYLINE")))

	     ;; selected anything but AECC_PARCEL_SEGMENT,LINE,LWPOLYLINE
	  
	  (ensel 		;; correct selection
	   
	   (or osp
	       (setq osp (getpoint "\nSpecify point on side to offset multiple lines: ")))

	   (command)
	   (command "_.OFFSET" dist (car ensel) "_none" osp "")
	   ;;;;;; while "Cannot offset that object." I would like to keep reseting the osp till it finds one it like.;;;;;;	
	   (ssadd (entlast) esmtlist)
	  )
	)
  )
  (princ)
)

(defun c:boo(/)

  (command 
    "PEDIT" "M" esmtlist "" "J" "100" ""	
  )
)

btw.

- not sure why Changepoint does not work correctly (in acad 2016 'c' is not highlighted and not able to select), i changed it to changePoint.

- Using (initget) for settings a distance is a legitimate tool. But remember one thing - you should not have to think about which you have defined by (initget) and which not... that's counterproductive... then it's better to get used to more complicated way but without need to think about.

 

If you would have some other problem then please post a dwg sample - especially with a parcel object.

0 Likes