Author Topic: redefine offset command  (Read 1807 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
redefine offset command
« on: April 01, 2016, 02:39:54 AM »
Hello to all,
I need to define the offset command, because I'd like to do some operations to results objects.
I wish the user could use all of the offset command options (Point / Delete / Multiple Layer ... ... etc.)
Unfortunately I have no idea how to do.

Code: [Select]
(defun c:newoffset ()
   (command "_.offset" pause pause pause ??????)
   (setq newogg (??????)
  [code that will handle the selection set 'newogg']

Can you help me?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: redefine offset command
« Reply #1 on: April 01, 2016, 07:07:45 AM »
Here is a solution:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:NewOffset ( / doc enm ss tmp)
  2.   (if
  3.     (or
  4.       (setq enm (entlast))
  5.       (progn
  6.         (princ "\nNo entity available for offset ")
  7.         nil
  8.       )
  9.     )
  10.     (progn
  11.       (if (= 8 (logand (getvar 'undoctl) 8))
  12.         (vla-endundomark doc)
  13.       )
  14.       (vla-startundomark doc)
  15.       (while (setq tmp (entnext enm))
  16.         (setq enm tmp)
  17.       )
  18.       (command "_.offset")
  19.       (while (/= 0 (logand (getvar 'cmdactive) 3))
  20.         (command pause)
  21.       )
  22.       (setq ss (ssadd))
  23.       (while (setq enm (entnext enm))
  24.         (ssadd enm ss)
  25.       )
  26.       (if (/= 0 (sslength ss))
  27.         (sssetfirst nil ss)
  28.       )
  29.       (vla-endundomark doc)
  30.     )
  31.   )
  32.   (princ)
  33. )
« Last Edit: April 01, 2016, 07:12:02 AM by roy_043 »

Lupo76

  • Bull Frog
  • Posts: 343
Re: redefine offset command
« Reply #2 on: April 03, 2016, 11:41:16 AM »
Here is a solution:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:NewOffset ( / doc enm ss tmp)
  2.   (if
  3.     (or
  4.       (setq enm (entlast))
  5.       (progn
  6.         (princ "\nNo entity available for offset ")
  7.         nil
  8.       )
  9.     )
  10.     (progn
  11.       (if (= 8 (logand (getvar 'undoctl) 8))
  12.         (vla-endundomark doc)
  13.       )
  14.       (vla-startundomark doc)
  15.       (while (setq tmp (entnext enm))
  16.         (setq enm tmp)
  17.       )
  18.       (command "_.offset")
  19.       (while (/= 0 (logand (getvar 'cmdactive) 3))
  20.         (command pause)
  21.       )
  22.       (setq ss (ssadd))
  23.       (while (setq enm (entnext enm))
  24.         (ssadd enm ss)
  25.       )
  26.       (if (/= 0 (sslength ss))
  27.         (sssetfirst nil ss)
  28.       )
  29.       (vla-endundomark doc)
  30.     )
  31.   )
  32.   (princ)
  33. )

Hello Roy,
thanks for your code!
It works very well but it has a small problem in AutoCAD, it does not display the preview of the result :oops:

Can you also solve this?  :roll:

Lupo76

  • Bull Frog
  • Posts: 343
Re: redefine offset command
« Reply #3 on: April 03, 2016, 12:11:29 PM »
I realized just now of a more serious problem.
With your code I can control the user-selected object only after the command has been completed.
In my first post I explained the problem badly.

I have to check that each user-selected object is confirmed to my needs.
A practical example is the OFFSET command that always works, except when the user selects an object LINE.

can you do this?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: redefine offset command
« Reply #4 on: April 04, 2016, 03:50:08 AM »
It works very well but it has a small problem in AutoCAD, it does not display the preview of the result :oops:

Can you also solve this?  :roll:
In BricsCAD V16 there is a preview. I don't know why AutoCAD behaves in this manner or how to solve it.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: redefine offset command
« Reply #5 on: April 04, 2016, 03:55:32 AM »
I realized just now of a more serious problem.
With your code I can control the user-selected object only after the command has been completed.
In my first post I explained the problem badly.

I have to check that each user-selected object is confirmed to my needs.
A practical example is the OFFSET command that always works, except when the user selects an object LINE.

can you do this?
If you want to validate the source entities, something like the code below will work. But it does not expose all options of the OFFSET command.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:NewOffset2 ( / N_GetEntity N_GetDistance dist doc enm enmOffset pt ss tmp)
  2.  
  3.   (defun N_GetEntity ( / enm)
  4.     (if
  5.       (and
  6.         (setq enm (car (entsel "\nSelect entity: ")))
  7.         (vl-position
  8.           (vla-get-objectname (vlax-ename->vla-object enm))
  9.           '("AcDb2dPolyline" "AcDbArc" "AcDbCircle" "AcDbEllipse" "AcDbLine" "AcDbPolyline" "AcDbSpline")
  10.         )
  11.       )
  12.       enm
  13.     )
  14.   )
  15.  
  16.   (defun N_GetDistance ( / dist)
  17.     (initget 6)
  18.     (setq dist
  19.       (getdist
  20.         (if (< 0 (getvar 'offsetdist))
  21.           (strcat "\nOffset distance <" (rtos (getvar 'offsetdist)) ">: ")
  22.           "\nOffset distance: "
  23.         )
  24.       )
  25.     )
  26.     (cond
  27.       (dist
  28.         (setvar 'offsetdist dist)
  29.         dist
  30.       )
  31.       ((< 0 (getvar 'offsetdist))
  32.         (getvar 'offsetdist)
  33.       )
  34.     )
  35.   )
  36.  
  37.   (if
  38.     (or
  39.       (setq enm (entlast))
  40.       (progn
  41.         (princ "\nNo entity available for offset ")
  42.         nil
  43.       )
  44.     )
  45.     (progn
  46.       (if (= 8 (logand (getvar 'undoctl) 8))
  47.         (vla-endundomark doc)
  48.       )
  49.       (vla-startundomark doc)
  50.       (while (setq tmp (entnext enm))
  51.         (setq enm tmp)
  52.       )
  53.       (if (setq dist (N_GetDistance))
  54.         (while
  55.           (and
  56.             (setq enmOffset (N_GetEntity))
  57.             (setq pt (getpoint "\nSide for parallel copy: "))
  58.           )
  59.           (setvar 'cmdecho 0)
  60.           (command "_.offset" dist enmOffset pt "")
  61.           (setvar 'cmdecho 1)
  62.         )
  63.       )
  64.       (setq ss (ssadd))
  65.       (while (setq enm (entnext enm))
  66.         (ssadd enm ss)
  67.       )
  68.       (if (/= 0 (sslength ss))
  69.         (sssetfirst nil ss)
  70.       )
  71.       (vla-endundomark doc)
  72.     )
  73.   )
  74.   (princ)
  75. )

ChrisCarlson

  • Guest
Re: redefine offset command
« Reply #6 on: April 04, 2016, 08:05:45 AM »
What additional functions do you want?

Lupo76

  • Bull Frog
  • Posts: 343
Re: redefine offset command
« Reply #7 on: April 04, 2016, 01:45:41 PM »
If you want to validate the source entities, something like the code below will work. But it does not expose all options of the OFFSET command.

The problem is just that!
I would like to validate the source objects and keep all the OFFSET command options  :cry: