Jump to content

Automatic offset of colored objects


Trap3d

Recommended Posts

Hello everyone,

 

I'm having trouble to create an automatic offset on all objects present on my drawing.

Based on the colours of the figures, i need to create offset with different distances.

For blue index 5 colour (0.0.255) and green index 3 colour (0.255.0), i need an offset of 0.3mm considering the edge of the blue object.

For yellow index 2 colour (255.255.0), i need an offset of 0.6mm considering the edge of the blue object.

 

spacer.png

 

Usually in my drawings i have multiple objects like this ones, and also more complex ones. i just need a code that creates all offsets automatically.

I really appreciate if anybody can create a lisp code that i can run on autocad 2020 to create all these automatic offsets.

Just to mention that the coloured objects aren't either polylines or hatches. But when i try do draw a polyline, i can select the edges of the objetcs. The objects are like on entire entity.

 

Thanks in advance.

Link to comment
Share on other sites

4 hours ago, Trap3d said:

Hello everyone,

 

I'm having trouble to create an automatic offset on all objects present on my drawing.

Based on the colours of the figures, i need to create offset with different distances.

For blue index 5 colour (0.0.255) and green index 3 colour (0.255.0), i need an offset of 0.3mm considering the edge of the blue object.

For yellow index 2 colour (255.255.0), i need an offset of 0.6mm considering the edge of the blue object.

 

spacer.png

 

Usually in my drawings i have multiple objects like this ones, and also more complex ones. i just need a code that creates all offsets automatically.

I really appreciate if anybody can create a lisp code that i can run on autocad 2020 to create all these automatic offsets.

Just to mention that the coloured objects aren't either polylines or hatches. But when i try do draw a polyline, i can select the edges of the objetcs. The objects are like on entire entity.

 

Thanks in advance.

@Trap3d, please upload your sample dwg  , as lisp should work in real and true cases.  

 

  • Like 1
Link to comment
Share on other sites

Thank you @devitg for your answer.

I send you an example of what usually appears and what i need to obtain.

I forgot to mention that when the objects are too close, the goal is to join them as a group so i only do 1 polygon surrounding them.

LISP example.dwg

Link to comment
Share on other sites

@Trap3d

1 hour ago, Trap3d said:

I forgot to mention that when the objects are too close, the goal is to join them as a group so i only do 1 polygon surrounding them.

How much too close . ?

 

 

 

  • Like 1
Link to comment
Share on other sites

52 minutes ago, devitg said:

@Trap3d

How much too close . ?

 

 

 

2mm i would say as the minimum distance between 2 adjacent elements.. The idea is to surround some "constellations" of elements in only one polygon like in the dxf file.

Thank you in advance for your help.

Link to comment
Share on other sites

48 minutes ago, Trap3d said:

2mm

@Trap3d, but at your sample constellations , items are far from 2mm distance 

 

image.png.b18d463501edc79c4dc9b2431f5f4e58.png

 What about if you pick the down left point and up right point  

 

 

 

 

Link to comment
Share on other sites

8 minutes ago, devitg said:

@Trap3d, but at your sample constellations , items are far from 2mm distance 

 

image.png.b18d463501edc79c4dc9b2431f5f4e58.png

 What about if you pick the down left point and up right point  

 

 

 

 

 

You right 2 mm is very short. 20mm I would say is the maximum value that it might happen.

It may also have different colours elements in between 2 different blue coloured. In that case, we cannot join different coloured elements in the same polygon. So this "boundary" is necessary.

 

spacer.png

 

The idea here is to create all polygons only with one command. Sometimes we have hundreds of polygons to make.

Link to comment
Share on other sites

Here you are :

 

(defun c:ssoffset ( / ss i e ll ur lls urs d )

  (vl-load-com)

  (prompt "\nSelect entities you want to enclose with offset lwpolyline...")
  (if (setq ss (ssget))
    (progn
      (repeat (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i))))
        (vla-getboundingbox (vlax-ename->vla-object e) 'll 'ur)
        (mapcar 'set '(ll ur) (mapcar 'safearray-value (list ll ur)))
        (setq lls (cons ll lls) urs (cons ur urs))
      )
      (setq ll (apply 'mapcar (cons 'min lls)))
      (setq ur (apply 'mapcar (cons 'max urs)))
      (initget 5)
      (setq d (getdist "\nPick or specify offset distance : "))
      (setq ll (list (- (car ll) d) (- (cadr ll) d)))
      (setq ur (list (+ (car ur) d) (+ (cadr ur) d)))
      (entmake
        (list
          (cons 0 "LWPOLYLINE")
          (cons 100 "AcDbEntity")
          (cons 100 "AcDbPolyline")
          (cons 90 4)
          (cons 70 (1+ (* 128 (getvar 'plinegen))))
          (cons 38 0.0)
          (cons 10 ll)
          (cons 10 (list (car ur) (cadr ll)))
          (cons 10 ur)
          (cons 10 (list (car ll) (cadr ur)))
          (list 210 0.0 0.0 1.0)
        )
      )
    )
  )
  (princ)
)

 

HTH.

M.R.

  • Like 1
Link to comment
Share on other sites

21 minutes ago, marko_ribar said:

Here you are :

 

(defun c:ssoffset ( / ss i e ll ur lls urs d )

  (vl-load-com)

  (prompt "\nSelect entities you want to enclose with offset lwpolyline...")
  (if (setq ss (ssget))
    (progn
      (repeat (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i))))
        (vla-getboundingbox (vlax-ename->vla-object e) 'll 'ur)
        (mapcar 'set '(ll ur) (mapcar 'safearray-value (list ll ur)))
        (setq lls (cons ll lls) urs (cons ur urs))
      )
      (setq ll (apply 'mapcar (cons 'min lls)))
      (setq ur (apply 'mapcar (cons 'max urs)))
      (initget 5)
      (setq d (getdist "\nPick or specify offset distance : "))
      (setq ll (list (- (car ll) d) (- (cadr ll) d)))
      (setq ur (list (+ (car ur) d) (+ (cadr ur) d)))
      (entmake
        (list
          (cons 0 "LWPOLYLINE")
          (cons 100 "AcDbEntity")
          (cons 100 "AcDbPolyline")
          (cons 90 4)
          (cons 70 (1+ (* 128 (getvar 'plinegen))))
          (cons 38 0.0)
          (cons 10 ll)
          (cons 10 (list (car ur) (cadr ll)))
          (cons 10 ur)
          (cons 10 (list (car ll) (cadr ur)))
          (list 210 0.0 0.0 1.0)
        )
      )
    )
  )
  (princ)
)

 

HTH.

M.R.

 

Thanks a lot @marko_ribar for your code. It worked just fine.

As far as i understood, your code always draws rectangles. But sometimes I require more complex polygons. I need always a polygon that is 0.3mm far form the closest blue point.

I can have other coloured elements in the surrounding, so that's why I'm referring this. Can you fix this issue?

 

1MGIF.png

 

Thanks in advance.

 

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