Jump to content

Offset to layer on particular side and erase orignal object offset from


Baber62

Recommended Posts

Hi,

 

Need help with this routine, it offsets to a selected layer however I need to add coding to erase the orginal object that it was offset from.

 

The coding is as listed below:

 

[/b]

;; OL.lsp
;; Offset-to-Layer = Offset an entity a specified distance, and Change the new entity to a specified Layer.
;; At first use, offers current Offset Distance and current Layer as defaults;
;; subsequently, offers this routine's previously-used Offset-to-Layer Distance (even if ordinary Offset
;; distance has been changed) and Layer-to-change-to as defaults.
;; by Kent Cooper, August 2008
(defun C:OL (/ offlaytemp offent)
(initget 134)
(setq
offlaydist
(cond
(
(getdist
(strcat
"\nOffset-to-Layer distance or [Through] <"
(cond
((numberp offlaydist) (rtos offlaydist))
((= (getvar 'offsetdist) -1) "Through")
((rtos (getvar 'offsetdist)))
); end cond
">: "
); end strcat
); end getdist
); end first cond test
(T (if (not offlaydist) (getvar 'offsetdist) offlaydist))
); end cond
offlaytemp
(getstring
(strcat
"\nLayer to Offset to <"
(if offlay offlay (getvar 'clayer))
">: "
); end strcat
); end getstring
offlay
(cond
((/= offlaytemp "") offlaytemp)
(offlay)
(T (getvar 'clayer))
); end cond
); end setq
(while
(not
(while
(not
(and
(setq offent (ssget ":S" '((0 . "LINE,ARC,CIRCLE,ELLIPSE,LWPOLYLINE,SPLINE,XLINE,RAY"))))
(= (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 (entget (ssname offent 0))))))) 0); 0 for Unlocked, 4 for Locked
); end and
); end not
(prompt "\nSelected Entity cannot be Offset, or is on a Locked Layer; try again: ")
); end while
); end not
(command "_.undo" "_be")
(command
".offset" offlaydist offent pause ""
".chprop" "l" "" "la" offlay ""
); end command
(command "_.undo" "_e")
); end while
); end defun
(princ "\nType OL to Offset to Layer.")
(princ)

[b]

 

 

Any help would be appreciated.

Edited by Baber62
Suggested by another user
Link to comment
Share on other sites

Why not just use the 'Layer' & 'Erase' options of the standard OFFSET command?

 

Specify offset distance or [Through/[color=blue]Erase[/color]/[color=red]Layer[/color]] <Through>:

 

PS: Please edit your post and enclose your code with code tags:

 

[highlight][noparse]

[/noparse][/highlight] Your code here [highlight][noparse]

[/noparse][/highlight]

Link to comment
Share on other sites

Hi Lee,

 

How would I go about using that in a lisp routine?

 

 

 

"Mathematics consists in proving the most obvious thing in the least obvious way." -- George Polya

Link to comment
Share on other sites

How would I go about using that in a lisp routine?

 

Here is an example to automatically set the options of the offset command to erase the original object and offset to the current layer:

 

(defun c:myoffset ( )
   (command "_.offset" "_E" "_Y" "_L" "_C")
   (while (< 0 (getvar 'cmdactive)) (command "\\"))
   (princ)
)

Using the existing options of the offset command avoids the need to reinvent the wheel for this task.

Additional code could very easily be added to set/reset the current layer before and after the offset command is called to offset to a layer of your choice.

Link to comment
Share on other sites

Here is an example to automatically set the options of the offset command to erase the original object and offset to the current layer:

 

(defun c:myoffset ( )
   (command "_.offset" "_E" "_Y" "_L" "_C")
   (while (< 0 (getvar 'cmdactive)) (command "\\"))
   (princ)
)

Using the existing options of the offset command avoids the need to reinvent the wheel for this task.

Additional code could very easily be added to set/reset the current layer before and after the offset command is called to offset to a layer of your choice.

 

Lee,

 

Taking this idea, how do I apply to so that a polyline with thickness I can do an offset to half the value of the variable plinewid?

I do not know another way to make a polyline with thickness can be drawn without being the center, so this would be an opportunity to do so.

To better understand, I attached a picture.

 

(defun c:ofpw (/ pw )
   (setq pw (/(getvar "plinewid") 2))
(setq pw (/ pw 2))
(command "_.offset" pw "_E" "_Y" "_L" "_C");; not work
   (while (< 0 (getvar 'cmdactive)) (command "\\"))
   (princ)
)

cadtutor_exp_3.jpg

Link to comment
Share on other sites

Hi teknomatika,

 

I have another code which I use to adjust various polylines to thickness, but your idea if developed further could prove useful i.e have an offset then adjust the thickness of the line. Perhaps someone might combine the codes together.

 


(Defun c:Plw (/ s ss sn i) 



(if (setq s  (ssadd)        
ss (ssget "_x" '((0 . "*POLYLINE") (8 . "Estate - AAT,Estate - Hatched area,Estate - Lockable gate, Estate - SYL")))    ;<<<<< Enter layer names separated by comma  
)    
(progn      
	(repeat (setq i (sslength ss))    
(setq sn (ssname ss (setq i (1- i))))    
(if (not (eq (cdr (assoc 100 (reverse (entget sn))))             
"AcDb3dPolyline"         
	)        
)      
(ssadd sn s)    
	)      
)      
(if (> (sslength s) 0)    
(command "_.pedit" "_m" s "" "w" 0.2 "")      
	)      
;(princ "\n .... ")      
;(princ (strcat "Number of Polylines changed : "
            " < "             
;(itoa (sslength s))             " > "         
;		)      
;	)    
)    
;(princ "\n Couldn't find any 2D polyline !!")  
)  
(princ)
)

Link to comment
Share on other sites

Taking this idea, how do I apply to so that a polyline with thickness I can do an offset to half the value of the variable plinewid?

 

Try something like this:

 

(defun c:ofpw ( / pw )
   (command "_.offset" "_E" "_Y" "_L" "_C")
   (if (< 0.0 (setq pw (getvar 'plinewid)))
       (command (/ pw 2.0))
   )
   (while (< 0 (getvar 'cmdactive)) (command "\\"))
   (princ)
)

Link to comment
Share on other sites

Lee,

 

This works great, but I am still struggling to get it to do what I want it to do, which is do an offset, erase the orignal line then change the layer of the offset line and the line width ... any help would be appreciated.

 

 

"Mathematics consists in proving the most obvious thing in the least obvious way." -- George Polya

Link to comment
Share on other sites

Lee,

 

It is exactly that.

Again, thank you.

 

You're welcome!

 

Lee,

 

This works great, but I am still struggling to get it to do what I want it to do, which is do an offset, erase the orignal line then change the layer of the offset line and the line width ... any help would be appreciated.

 

The layer assignment can be quite easily achieved with my existing code by setting the current layer to the desired layer (CLAYER System Variable) before calling the offset command, and then resetting the current layer following evaluation of the offset command.

 

However, setting the 'line width' (I would assume you mean LWPolyline width) may require a restricted selection before calling the offset command and then operating on the offset entity by calling the entlast function following the offset command.

 

What do you have so far?

Link to comment
Share on other sites

Lee,

 

Haven't had much time to look at the routine, not proficient enough with lisp as yet ... still learning the ropes. That's why I'm having to use the two separate routines one to offset the layer to and then run the plw to change the thicknesses. Tried to adjust your coding but without success. Gone through about six different codings but all without success. Also looked up the coding you put in first command line but didn't get very far with either.

 

 

 

"Mathematics consists in proving the most obvious thing in the least obvious way." -- George Polya

Link to comment
Share on other sites

The following will set the required layer to be current before calling the offset command (as described earlier):

 

(defun c:myoffset ( / layer oldlay )

   (setq layer "Your Layer") ;; Layer to be used for offset

   (setq oldlay (getvar 'clayer))
   (if (null (tblsearch "LAYER" layer))
       (command "_.-layer" "_M" layer "")
       (command "_.-layer" "_T" layer "_U" layer "_S" layer "")
   )
   (command "_.offset" "_E" "_Y" "_L" "_C")
   (while (< 0 (getvar 'cmdactive)) (command "\\"))
   (setvar 'clayer  oldlay)
   (princ)
)

The above will first check for the existence of the layer and create it if necessary.

 

I have kept the code relatively simple by using a call to the -layer command rather than creating and manipulating the layers using entmake or Visual LISP methods, so that you might better understand what the code is doing.

 

Regarding the change of polyline width, this will require a little more modification.

Link to comment
Share on other sites

Thanks Lee appreciated.

 

 

 

 

"Mathematics consists in proving the most obvious thing in the least obvious way." -- George Polya

Link to comment
Share on other sites

Lee,

 

Never having been sort of the guy who gives up ... I was looking and looking and came across this link:

 

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Offset-Polyline-and-adjust-Global-Width/td-p/2268575

 

This resolves the issue of changing the polyline width. I'll give it a go combining your code and this guys code and post the results in the morning, and hopefully some coding.

 

 

 

 

"Mathematics consists in proving the most obvious thing in the least obvious way." -- George Polya

Link to comment
Share on other sites

Hi Lee,

 

Spent most of the weekend trying this in various ways without any success ... not being proficient in LISP doesn't help I know but still having problems to get this to change the layer from source to target.

 

I also had a look at the DYNOFF funtion that you had created. That works great but it changes the polyline thickness for printing purposes, not for screen display mode.

 

Any advice would be gratefully appreciated.

 

 

 

 

"Mathematics consists in proving the most obvious thing in the least obvious way." -- George Polya

Link to comment
Share on other sites

...still having problems to get this to change the layer from source to target.

 

My earlier code should demonstrate how to set the layer before using the offset command; alternatively, you can separately change the layer of the offset object which may be obtained using the entlast function, following the call to the offset command.

 

What do you currently have?

Link to comment
Share on other sites

Hi Lee,

 

This is the stage where I'm at ...

 

(defun c:myoffset2 (/ layer oldlay)
(setq layer "\nEnter Layer") ;; Layer to be used for offset
   (setq oldlay (getvar 'clayer))
   (if (null (tblsearch "LAYER" layer))
       (command "_.-layer" "_M" layer "")
       (command "_.-layer" "_T" layer "_U" layer "_S" layer "")
   )
   (command "_.offset" "_E" "_Y" "_L" "_C")         ;;need to specify offset at this stage 
   (while (< 0 (getvar 'cmdactive)) (command "\\"))
   (setvar 'clayer  oldlay)
(setq PL (entlast))
(setq width "\nEnter polyline thickness")
(setq Element (entget PL))
(setq Element (subst (cons 43 width) (assoc 43 Element) Element)) 
(entmod Element)
(entupd ename)
(princ)
)

 

Not sure how to proceed further at the moment.

 

 

 

"Mathematics consists in proving the most obvious thing in the least obvious way." -- George Polya

Link to comment
Share on other sites

Here's a nudge in the right direction...

 

(defun c:myoffset3 ( / ent lay wid )
   
[i][color=green]    ;; Prompt user for layer for offset object[/color][/i]
   (while
       (and
           (/= "" (setq lay (getstring t (strcat "\nSpecify Layer for Offset Object <" (getvar 'clayer) ">: "))))
           (not (snvalid lay))
       )
       (princ "\nInvalid layer name.")
   )
   (if (= "" lay)
       (setq lay (getvar 'clayer))
   )

[color=green][i]    ;; Prompt user for Polyline Width[/i][/color]
   (initget 4)
   (setq wid (getdist "\nSpecify Polyline Width <0.0>: "))
   (if (null wid)
       (setq wid 0.0)
   )

[i][color=green]    ;; Start Offset command[/color][/i]
   (command "_.offset" "_E" "_Y")
   (while (< 0 (getvar 'cmdactive)) (command "\\"))

[i][color=green]    ;; Modify Offset entity[/color][/i]
   (if
       (and
           (setq ent (entlast))
           (= "LWPOLYLINE" (cdr (assoc 0 (setq ent (entget ent)))))
       )
       (entmod
           (subst (cons 43 wid) (assoc 43 ent)
               (subst (cons 08 lay) (assoc 08 ent) ent)
           )
       )
   )
[i][color=green]
   ;; Suppress return of last expression[/color][/i]
   (princ)
)

Link to comment
Share on other sites

Hi Lee,

 

Brilliant ... that does the trick. Thank you for your time in helping to resolve this issue.

 

 

 

 

Mathematics consists in proving the most obvious thing in the least obvious way." -- George Polya

Link to comment
Share on other sites

Hi Lee,

 

Just one more thing ... sorry to bug you like this.

 

How do I store the old variables for the offset command and then at the end of the routine restore them.

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