Author Topic: Dynamic Offset  (Read 49188 times)

0 Members and 2 Guests are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dynamic Offset
« Reply #45 on: December 11, 2009, 10:48:55 AM »
Here is 2 versions to play with for offset to center between 2 lines...
Code: [Select]

;;; http://www.theswamp.org/index.php?topic=29537.0
;;; Patrick_35, GILE
;;; MsgBox
(defun ARCH:MsgBox2 (title buttons message time / return WshShell)
  (setq WshShell (vlax-create-object "WScript.Shell"))
  (setq return (vlax-invoke
  WshShell
  'Popup
  message
  time
  title
  (itoa buttons)
)
  )
  (vlax-release-object WshShell)
  return
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Select Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ARCH:SELECT-1  ()
  (while (or (not (setq sel1 (entsel "\n* Select Object *")))
             (and (/= (cdr (assoc 0 (setq ent (entget (car sel1))))) "LINE")
                  (/= (cdr (assoc 0 (setq ent (entget (car sel1))))) "POLYLINE")
                  (/= (cdr (assoc 0 (setq ent (entget (car sel1))))) "LWPOLYLINE")))
    (ARCH:MsgBox2 " Arch Program : Error" 16 "
     Selection Error Message
--------------------------------------------------------------------------------------------
     You did not Select Anything. Please try again." 4))
  (princ))
(defun ARCH:SELECT-2  ()
  (while (or (not (setq sel2 (entsel "\n* Select Object *")))
             (and (/= (cdr (assoc 0 (setq ent (entget (car sel2))))) "LINE")
                  (/= (cdr (assoc 0 (setq ent (entget (car sel2))))) "POLYLINE")
                  (/= (cdr (assoc 0 (setq ent (entget (car sel2))))) "LWPOLYLINE")))
    (ARCH:MsgBox2 " Arch Program : Error" 16 "
     Selection Error Message
--------------------------------------------------------------------------------------------
     You did not Select Anything. Please try again." 4))
  (princ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;; Center Between Lines Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ARCH:CEN-BETWEEN-LIN  (/ p1 p2 p3 obj1 obj2)
  (ARCH:SELECT-1)
  (setvar "osmode" 0)
  ;;(princ "\n* Single wall fill *") 
  (setq obj1 (car sel1))
  (setq p1 (car (cdr sel1)))
  (ARCH:SELECT-2)
  (setq obj2 (car sel2))
  (setq p2 (car (cdr sel2)))
  (command "dist" "nea" p1 "per" p2)
  (setq dist_1 (getvar "distance"))
  (setq dist_2 (/ dist_1 2.0))
  (setq x (/ (+ (car p1) (car p2)) 2))
  (setq y (/ (+ (cadr p1) (cadr p2)) 2))
  (setq z (/ (+ (caddr p1) (caddr p2)) 2))
  (setq p3 (list x y z))
  (command ".offset" dist_2 obj1 p3 "")
  (princ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; New Wall Fill Routine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ARCH:CEN-BETWEEN-LIN2  (/ a b p1 p2 pt ent1 ent2 ent3)
  ;;(if (not ARCH:GetIntersect)(load (strcat ARCH#UTIF "ARCH_GET_INTERSECT")))
  (defun CEN-BETWEEN-LIN-DOIT  ()
    (command "line" a b "")
    (setq ent1 (entlast))
    (cond (SS1
           (repeat (sslength SS1)
             (setq ent2 (cdr (assoc -1 (entget (ssname SS1 0)))))
             (setq p1 (ARCH:GetIntersect ent1 ent2))
             (setq ent3 (cdr (assoc -1 (entget (ssname SS1 1)))))
             (setq p2 (ARCH:GetIntersect ent1 ent3)))))
    (command "dist" "nea" p1 "per" p2)
    (setq dist_1 (getvar "distance"))
    (setq dist_2 (/ dist_1 2.0))
    (setq x (/ (+ (car p1) (car p2)) 2))
    (setq y (/ (+ (cadr p1) (cadr p2)) 2))
    (setq z (/ (+ (caddr p1) (caddr p2)) 2))
    (setq p3 (list x y z))
    (command ".offset" dist_2 ent2 p3 "")
    (entdel ent1)
    (princ))
  (setvar "orthomode" 0)
  (setvar "osmode" 0)
  ;;(initget 1)
  (setq a (getpoint "\n* Draw Crossing Line *"))
  (initget 33)
  (setq b (getpoint a))
  (setq pt (list a b))
  (setq SS1 (ssget "F" pt '((0 . "LINE"))))
  (cond
    ((or (= SS1 nil) (/= (sslength SS1) 2))
     (ARCH:MsgBox2 " Arch Program : Error" 16 "
     Selection Error Message
--------------------------------------------------------------------------------------------
     Invalid Selection...either you selected nothing, a
     double line <line on top of a line>, or a polyline.
     If a double line, delete one, or if a polyline
     change it to a line. Now you can try again..." 4))
    ((CEN-BETWEEN-LIN-DOIT)))
  (princ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;; Get the Intersection Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;One of the better ways is to use the IntersectWith method:
;;;Written by R. Robert Bell
;;;Takes either ENames or Objects, returns list or nil.
(defun ARCH:GetIntersect (obj1 obj2)
  (foreach
         obj '(obj1 obj2)
    (if (= (type (eval obj)) 'ENAME)
      (set obj
           (vlax-EName->vla-Object
             (eval obj)
           )
      )
    )
  )
  (vlax-Invoke obj1 'IntersectWith obj2 acExtendBoth)
)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: Dynamic Offset
« Reply #46 on: December 11, 2009, 10:55:45 AM »
Thanks Gary  :-)

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: Dynamic Offset
« Reply #47 on: December 14, 2009, 09:45:43 AM »
I have updated the code in the first post to Version 1.8. This version incorporates Gary's idea to allow the user to offset to the center of two objects.

Enjoy!

Lee

t-bear

  • Guest
Re: Dynamic Offset
« Reply #48 on: December 14, 2009, 09:53:00 AM »
This routine is getting sweeter all the time!  Thanks all, and thanks Lee for getting the ball rolling.  Nice things happen when you folks put yor heads together....love this place!

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: Dynamic Offset
« Reply #49 on: December 14, 2009, 09:59:20 AM »
Thanks t-Bear  8-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Dynamic Offset
« Reply #50 on: December 14, 2009, 10:09:47 AM »
Just so you know, if you select both lines, then execute centerline offset, you will get 2 lines in the center.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

xianaihua

  • Guest
Re: Dynamic Offset
« Reply #51 on: December 14, 2009, 10:11:12 AM »
Nice routine- I like
thanks! :love: :love:

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: Dynamic Offset
« Reply #52 on: December 14, 2009, 10:13:19 AM »
Just so you know, if you select both lines, then execute centerline offset, you will get 2 lines in the center.

Yes - I thought this would be more consistent with the rest of the program  :-)

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: Dynamic Offset
« Reply #53 on: December 14, 2009, 10:13:35 AM »
Nice routine- I like
thanks! :love: :love:

Thanks  xianaihua  8-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Dynamic Offset
« Reply #54 on: December 14, 2009, 10:17:17 AM »
Just so you know, if you select both lines, then execute centerline offset, you will get 2 lines in the center.

Yes - I thought this would be more consistent with the rest of the program  :-)
To have 2 lines on top of one another?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: Dynamic Offset
« Reply #55 on: December 14, 2009, 10:20:44 AM »
Just so you know, if you select both lines, then execute centerline offset, you will get 2 lines in the center.

Yes - I thought this would be more consistent with the rest of the program  :-)
To have 2 lines on top of one another?

Only if you select both lines in the first place - say you want to offset both lines to the outside...

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Dynamic Offset
« Reply #56 on: December 14, 2009, 10:26:09 AM »
Just so you know, if you select both lines, then execute centerline offset, you will get 2 lines in the center.

Yes - I thought this would be more consistent with the rest of the program  :-)
To have 2 lines on top of one another?

Only if you select both lines in the first place - say you want to offset both lines to the outside...

...but I would still want to avoid ending up with 2 lines atop one another. It's your program, I'm just making a suggestion, based on what I would change.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: Dynamic Offset
« Reply #57 on: December 14, 2009, 10:37:20 AM »
Just so you know, if you select both lines, then execute centerline offset, you will get 2 lines in the center.

Yes - I thought this would be more consistent with the rest of the program  :-)
To have 2 lines on top of one another?

Only if you select both lines in the first place - say you want to offset both lines to the outside...

...but I would still want to avoid ending up with 2 lines atop one another. It's your program, I'm just making a suggestion, based on what I would change.

True - I understand your point - but I think I will keep the program as is - I realise that you wouldn't want two lines above each other, but it just seems more logical that if you select two lines to offset, you will get two offsets.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Dynamic Offset
« Reply #58 on: December 14, 2009, 10:45:15 AM »
Just so you know, if you select both lines, then execute centerline offset, you will get 2 lines in the center.

Yes - I thought this would be more consistent with the rest of the program  :-)
To have 2 lines on top of one another?

Only if you select both lines in the first place - say you want to offset both lines to the outside...

...but I would still want to avoid ending up with 2 lines atop one another. It's your program, I'm just making a suggestion, based on what I would change.

True - I understand your point - but I think I will keep the program as is - I realise that you wouldn't want two lines above each other, but it just seems more logical that if you select two lines to offset, you will get two offsets.
Fare enough.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: Dynamic Offset
« Reply #59 on: December 16, 2009, 07:21:13 AM »
Following a suggestion from over at CADTutor, I have updated the code in the first post to Version 1.9.

In this version, I have altered the way that the program deals with multiple offsets, and have made an important bug fix for the OSnap.

Enjoy,

Lee