Jump to content

Recommended Posts

Posted

I have a lisp to offset a line by 5mm, and change the layer. What i want it to do is offset the line by 5mm and 10mm, so in the end there will be 3 lines. I want the two offset lines to be on the same layer, and also a different colour and linetype (the 5mm offset line "cyan" "awthidden2" (the linetype), the 10mm offset line "red" "continuous"). Here is the code which offsets a line by 5mm and changes the layer, what do i have to add to also get it to offset 10mm and change the layer and linetypes?

 

(defun c:membrane (/ ent pt)
(while (and
(setq ent (car (entsel "\nSelect object to offset 5 or <exit>:")))
(setq pt (getpoint "\nSpecify point on side to offset:"))
)
(command "._offset" 5.00 ent "_non" pt "")
(command "._change" (entlast) "" "_P" "_LA" "Membrane" "")
)
(princ)
)

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    15

  • gazzalp

    8

  • AustinTECH

    2

  • CAB

    1

Posted

maybe this?

 

(defun c:membrane (/ ent pt l1 l2)
   (setq oldlay (getvar "clayer"))
   (while (and
          (setq ent (car (entsel "\nSelect object to offset 5 or <exit>:")))
          (setq pt (getpoint "\nSpecify point on side to offset:"))
      ) ;_  end and
   (if (not (tblsearch "Layer" "Membrane"))
       (command "-layer" "m" "Membrane" "")
       (setvar "clayer" "Membrane")
   ) ;_  end if
   (command "._offset" 5.00 ent "_non" pt "")
   (setq l1 (entlast))
   (command "._offset" 10.00 l1 "_non" pt "")
   (setq l2 (entlast))
   (command "_chprop" l1 "" "c" "cyan" "lt" "awthidden2" "")
   (command "_chprop" l2 "" "c" "red" "lt" "continuous" "")
   ) ;_  end while
   (setvar "clayer" oldlay)
   (princ)
) ;_  end defun

Posted

Thanks Lee, it didnt work 100%, it offset the first line 5mm, then the second 10mm instead of the first 5 and 10mm, but i changed it and it works fine. Also it didnt change the layer, any idea why that may be? Thanks very much for your help. If you ever come to Australia beers are on me :)

Posted

When you say it didn't change the layer... do you mean the lines aren't on the correct layer when offset? Or that it didn't reset back to the original current layer?

 

Thanks for the beers - I didn't realise you were in Australia - no wonder you are always active at this time of night... :P

Posted

When the two lines are offset, they change colour etc, but not change layer. Ideally it would be good if they were changed to "membrane" but they dont at the moment. Yeah im in aus, im not an owl :P

Posted

Very sorry Gazzalp, I didn't test that last LISP on my machine as I don't have the necessary linetypes etc.

 

Anyway, this should work:

 

(defun c:membrane (/ ent pt l1 l2)
   (setq oldlay (getvar "clayer"))
   (while (and
          (setq ent (car (entsel "\nSelect object to offset 5 or <exit>:")))
          (setq pt (getpoint "\nSpecify point on side to offset:"))
      ) ;_  end and
   (if (not (tblsearch "Layer" "Membrane"))
       (command "-layer" "m" "Membrane" "")
   ) ;_  end if
   (command "._offset" 5.00 ent "_non" pt "")
   (setq l1 (entlast))
   (command "._offset" 10.00 ent "_non" pt "")
   (setq l2 (entlast))
   (command "_chprop" l1 "" "c" "cyan" "lt" "awthidden2" "la" "Membrane" "")
   (command "_chprop" l2 "" "c" "red" "lt" "continuous" "la" "Membrane" "")
   ) ;_  end while
   (setvar "clayer" oldlay)
   (princ)
) ;_  end defun

 

Yeah im in aus, im not an owl :P

 

Well... the thought had crossed my mind... :P

Posted

thats better, thanks Lee. Your next mission should you choose to accept it, is say for example i have a horiz. line, then a line on the end of that on a 45 degree angle IE: _/ i want to be able to use that macro on both lines, AND have the new lines fillet to each other. Is that at all possible? and also i have situations where that might continue for quite a few angle changes, so it would be good that anytime i offset, it fillets to the other lines next to it (not sure if this is possible, especially considering its for sections; and as an example section 1 might look like _/\_ and i want all those lines filleted, but its not like you can just write it into the program that anytime these new lines are added they need to be filleted (because section two might need these lines, and i obviously cant have them filleted/joining onto section 1) but maybe have it so that it keeps offsetting untill i press enter, and when thats done all the previous filleted lines are joined. Thats alot of explaining for such a simple question...

Posted

Sure: top is what the lines will look like before offset, the bottom is what i want it to look like (so the macro already offsets the lines, im wondering if it can fillet them as well, like in the drawing ive uploaded)

membrane.dwg

Posted

OK, I have a LISP that will automatically offset all your lines for you, but I can't work out how to fillet all of the offset lines - how to tell ACAD which lines are filleted with which and also, how to store all the newly created lines.

 

but give this a go:

 

(defun c:membrane (/ *error* varLst oldVars ss ssl index lins pt ent1 ent l1 l2)

 ;     --- Error Trap ---

   (defun *error* (msg)
   (mapcar 'setvar varLst oldVars)
   (if (= msg "")
       (princ "\nFunction Complete.")
       (princ "\nError or Esc pressed... ")
   ) ;_  end if
   (princ)
   ) ; end of *error*

   (setq varLst  (list "CMDECHO" "CLAYER" "FILLETRAD")
     oldVars (mapcar 'getvar varLst)
   ) ; end setq 

 ;    --- Error Trap ---

   (setvar "cmdecho" 0)
   (makelay "Membrane")
   (setq ss    (ssget)
     ssl    (sslength ss)
     index    0
     lins    0
   ) ;_  end setq
   (if
   (setq pt (getpoint "\nSelect Point on Side of Lines to Offset: "))
      (progn
          (repeat ssl
          (setq ent (ssname ss index))
          (setq ent1 (entget ent))
          (if (= "LINE" (cdr (assoc 0 ent1)))
              (progn
              (command "_offset" "5.0" ent pt "")
              (setq l1 (entlast))
              (command "_chprop" l1 "" "la" "Membrane" "c" "cyan" "lt" "awthidden2" "")
              (command "_offset" "5.0" l1 pt "")
              (setq l2 (entlast))
              (command "_chprop" l2 "" "la" "Membrane" "c" "red" "lt" "continuous" "")
              (setq lins (1+ lins))
              ) ;_  end progn
          ) ;_  end if
          (setq index (1+ index))
          ) ;_  end repeat
      ) ;_  end progn
      (alert "Please Select a Point.")
   ) ;_  end if
   (if    (= 1 lins)
   (princ (strcat "\n" (itoa lins) " Line Offset."))
   (princ (strcat "\n" (itoa lins) " Lines Offset."))
   ) ;_  end if
   (*error* "")
   (princ)
) ;_  end defun

;;; I gave up at this point... 

;;;        (setvar "filletrad" 0)
;;;        (setq ang1 (angget l1))
;;;        (setq ang2 (angget l2))
;;;        (setq mid1 (polar (cdr (assoc 10 l1)) ang1 (/ (len l1) 2)))
;;;        (setq mid2 (polar (cdr (assoc 10 l2)) ang2 (/ (len l2) 2)))
;;;        (command "_fillet" 


(defun makelay (lay)
   (if    (not (tblsearch "Layer" lay))
   (command "-layer" "m" lay "")
   ) ;_  end if
) ;_  end defun
(defun angget (lin)
   (angle (cdr (assoc 10 lin)) (cdr (assoc 11 lin)))
) ;_  end defun
(defun len (a)
   (distance (cdr (assoc 10 a)) (cdr (assoc 11 a)))
) ;_  end defun

Posted

Works fine Lee, thanks :) i would have thought it could be done by, anytime you offset lines they will fillet, untill you press enter (and then could move onto a new section). but if this is too hard dont worry about it. Thanks for your help. I must owe you two cases by now...

Posted

Its the way the selection set works, it would be hard to tell which lines need to be filleted with which.

Posted

We try not to use polylines...Anyway what the program does is still good, thanks heaps for your help.

Posted
We try not to use polylines...Anyway what the program does is still good, thanks heaps for your help.

 

No probs, happy to be of assistance

Posted

Lee Mac,

Change the original lines to a pline, offset as needed, then explode all. :)

Posted

Cheers Cab,

When I get a minute I'll have a look at altering my Lisp, thanks for the tip!

Posted

Ok Gazzalp,

 

Using a the tip kindly recommended by CAB, I have come up with this:

 

(defun c:membrane (/ *error* varLst oldVars ss ssl l1 pt l2 l3)

 ;     --- Error Trap ---

   (defun *error* (msg)
   (mapcar 'setvar varLst oldVars)
   (command "_explode" l1)
   (if (= msg "")
       (princ "\nFunction Complete.")
       (princ "\nError or Esc pressed... ")
   ) ;_  end if
   (princ)
   ) ; end of *error*

   (setq varLst  (list "CMDECHO" "CLAYER")
     oldVars (mapcar 'getvar varLst)
   ) ; end setq 

 ;    --- Error Trap ---

   (setvar "cmdecho" 0)
   (makelay "Membrane")
   (setq ss  (ssget)
     ssl (sslength ss)
   ) ;_  end setq
   (if    (= ssl 1)
   (command "_pedit" ss "Y" "")
   (command "_pedit" "M" ss "" "Y" "J" "" "")
   ) ;_  end if
   (setq l1 (entlast))
   (if
   (setq pt (getpoint "\nSelect Point on Side of Lines to Offset: "))
      (progn
          (command "_offset" "5.0" l1 pt "")
          (setq l2 (entlast))
          (command "_chprop" l2 "" "la" "Membrane" "c" "cyan" "lt" "awthidden2" "")
          (command "_offset" "5.0" l2 pt "")
          (setq l3 (entlast))
          (command "_chprop" l3 "" "la" "Membrane" "c" "red" "lt" "continuous" "")
      ) ;_  end progn
      (alert "Please Select a Point.")
   ) ;_  end if
   (command "_explode" l1)
   (command "_explode" l2)
   (command "_explode" l3)
   (princ)
) ;_  end defun

(defun makelay (lay)
   (if    (not (tblsearch "Layer" lay))
   (command "-layer" "m" lay "")
   ) ;_  end if
) ;_  end defun

Posted

Thats Great Lee, works excellent. Thanks to you and CAB :)

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