Jump to content

Offset inside a polygon. and change appointment layer, many objects. LISP plz.


Recommended Posts

Posted

Dear Guys~

 

Offset inside a polygon. and change appointment layer, many objects. LISP plz.

 

See attatched DWG file. plz.

sample.dwg

Posted

Using this as a base .. here you go.

(defun c:foo (/ _off d o od p s x)
 ;; RJP » 2018-07-26
 ;; Offsets a pline inside or out an places the result on layer '3'
 (defun _off (o d / r)
   (cond ((= 'list (type (setq r (vl-catch-all-apply 'vlax-invoke (list o 'offset d))))) (car r)))
 )
 (cond	((and (not (initget "Outside Inside"))
      (setq p (cond ((getkword "\nOffset [Outside/Inside] <Inside>: "))
		    ("Inside")
	      )
      )
      (setq od (cond ((getdist "\nEnter offset distance: <1.5>"))
		     (1.5)
	       )
      )
      (setq s (ssget ":L" '((0 . "lwpolyline") (-4 . ">") (90 . 2))))
 )
 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
   (setq o (vlax-ename->vla-object e))
   (setq
     o (mapcar '(lambda (x) (cond ((setq d (_off o (x od))) (list d (vlax-curve-getarea d)))))
	       (list + -)
       )
   )
   (cond ((= 2 (length (setq o (vl-remove 'nil o))))
	  (setq o (vl-sort o '(lambda (r j) (< (last r) (last j)))))
	  (cond ((= p "Outside") (setq o (reverse o))))
	  (vla-delete (caadr o))
	  (setq o (entget (vlax-vla-object->ename (caar o))))
	  ;; Put object on layer '3'
	  (entmod (append o '((8 . "3"))))
	 )
	 ((and o (mapcar 'vla-delete (mapcar 'car o)))
	  (print "Could not determine inside or out...")
	 )
   )
 )
)
 )
 (princ)
)
(vl-load-com)

  • Like 2
Posted

Thank you for your response~. correctly worked. thank you thank you~

  • 2 years later...
Posted (edited)

Can anyone make the code by ronjonp work for Lines and Arcs.

Edited by sketch11
Posted

For a line its easy you pick an end then you compare the start and end of line to the pick point so know direction this results in knowing left or right direction for a offset. for an arc its a + or - offset so resulting in new radius.

Posted

For a selection of lines the task 'Offset inside' makes no sense.

  • Like 2
Posted
Quote

For a selection of lines the task 'Offset inside' makes no sense.

 

OK, I thought the Lines/Arcs may be easier than polygons.

It looks like it's not the case.

I'll just have to do it item by item.

Thanks for the responses.

 

 

Posted

Looking at your drawing you have asked maybe the wrong question 1st part should be make the plines automatically with a gap and 2nd part do offset at same time.

 

(setq obj (vlax-ename->vla-object (car  (entsel "Pick obj")))) ; do this as either (entlast) or a selection (ssname ss x)
(vla-offset obj 1.5)
(command "chprop" "l" "" "la" "appointment layer" "")

Are the panels always 283 wide ? How do you define the outer shape ?

 

  • 2 years later...
Posted (edited)

how can i change the layer name of all objects

Edited by Batuhan Anyığ
language is not english
Posted (edited)
1 hour ago, Batuhan Anyığ said:

how can i change the layer name of all objects

image.png.06de4bb6409efc52189a5fc0dd0cf728.png

 

Edited by ronjonp
  • 2 months later...
Posted
On 7/26/2018 at 3:06 PM, ronjonp said:

Using this as a base .. here you go.

 

(defun c:foo (/ _off d o od p s x)
 ;; RJP » 2018-07-26
 ;; Offsets a pline inside or out an places the result on layer '3'
 (defun _off (o d / r)
   (cond ((= 'list (type (setq r (vl-catch-all-apply 'vlax-invoke (list o 'offset d))))) (car r)))
 )
 (cond	((and (not (initget "Outside Inside"))
      (setq p (cond ((getkword "\nOffset [Outside/Inside] <Inside>: "))
		    ("Inside")
	      )
      )
      (setq od (cond ((getdist "\nEnter offset distance: <1.5>"))
		     (1.5)
	       )
      )
      (setq s (ssget ":L" '((0 . "lwpolyline") (-4 . ">") (90 . 2))))
 )
 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
   (setq o (vlax-ename->vla-object e))
   (setq
     o (mapcar '(lambda (x) (cond ((setq d (_off o (x od))) (list d (vlax-curve-getarea d)))))
	       (list + -)
       )
   )
   (cond ((= 2 (length (setq o (vl-remove 'nil o))))
	  (setq o (vl-sort o '(lambda (r j) (< (last r) (last j)))))
	  (cond ((= p "Outside") (setq o (reverse o))))
	  (vla-delete (caadr o))
	  (setq o (entget (vlax-vla-object->ename (caar o))))
	  ;; Put object on layer '3'
	  (entmod (append o '((8 . "3"))))
	 )
	 ((and o (mapcar 'vla-delete (mapcar 'car o)))
	  (print "Could not determine inside or out...")
	 )
   )
 )
)
 )
 (princ)
)
(vl-load-com)
 

 

 

Hi @ronjonp your code is great :)

 

I was testing on some closed plines that i have.

if the input pline is a bit of a complex geometry, the resulting offsetted pline can be divided in 2. (see attached example)

If that happens, only one of the resulting plines will move to the defined layer.

How can the code be modified so all resulting plines are moving to the defined layer?

 

OFFSET_PLINE.dwg

Posted
1 hour ago, Trap3d said:

How can the code be modified so all resulting plines are moving to the defined layer?

Set the defined layer current via (setvar 'clayer "3") then reset it back at the end to previous layer.

  • Like 1
Posted (edited)

Or, use this Ron's mod. by me...

 

(defun c:offslws-out-ins-putlayer (/ _off d o od p s x)

  (vl-load-com)

  ;; RJP » 2018-07-26
  ;; Offsets a pline inside or out an places the result on layer '3'
  (defun _off (o d / r)
   (cond ((= 'list (type (setq r (vl-catch-all-apply 'vlax-invoke (list o 'offset d))))) r))
  )
  (cond	((and 
          (not (initget "Outside Inside"))
          (setq p (cond ((getkword "\nOffset [Outside/Inside] <Inside>: ")) ("Inside")))
          (setq od (cond ((getdist "\nEnter offset distance: <1.5>")) (1.5)))
          (setq s (ssget ":L" '((0 . "lwpolyline") (-4 . ">") (90 . 2))))
        )
        (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
          (setq o (vlax-ename->vla-object e))
          (setq o (append (_off o (+ od)) (_off o (- od))))
          (setq o (mapcar '(lambda (x) (list x (vlax-curve-getarea x))) o))
          (cond
            ((>= (length (setq o (vl-remove 'nil o))) 2)
             (setq o (vl-sort o '(lambda (r j) (> (last r) (last j)))))
             (cond
              ((= p "Outside")
               (mapcar '(lambda (x) (vla-delete (car x))) (cdr o))
               (setq o (entget (vlax-vla-object->ename (caar o))))
               ;; Put object on layer '3'
               (entupd (cdr (assoc -1 (entmod (subst (cons 8 "3") (assoc 8 o) o)))))
              )
              ((= p "Inside")
               (entdel (vlax-vla-object->ename (caar o)))
               (setq o (cdr o))
               ;; Put object(s) on layer '3'
               (mapcar '(lambda (x) (entupd (cdr (assoc -1 (entmod (subst (cons 8 "3") (assoc 8 x) x))))))
                (mapcar '(lambda (y) (entget (vlax-vla-object->ename y)))
                 (mapcar 'car o)
                )
               )
              )
             )
            )
            ((and o (mapcar 'vla-delete (mapcar 'car o)))
             (print "Could not determine inside or out...")
            )
          )
        )
       )
  )
  (princ)
)

 

HTH., M.R.

Edited by marko_ribar
  • Like 1

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