Jump to content

Recommended Posts

Posted

Can anyone help me, probably this question has already been answered but I didn't find it in my google searches.

How can I grid a point grid on a closed polyline by determining the X and Y distances.
$-Select polyline
$-distance X
$-distance Y

and it inserts the points inside the polyline. Similar to the attached image.

Note: Hatching does not work.

 

image.thumb.png.029bb545418d8a251b5a36e799a37664.png

Posted

What if your X Y distances don't evenly divide into the area ?

Posted (edited)

Like ronjonp its an Array answer and can be done very easy,  just enter X & Y spacing and a edge rule min gap. A lisp is required or get your calculator out, a pen and paper will be required.

 

Will it always be circles ?

 

 

Edited by BIGAL
Posted

Its not rocket science an example

 

L=100

Max offset = 10

X space = 7.5

100-2xoff = 80

80/ 7.5 = 10.666666

round up to 11

100-11*7.5 = 82.5

Xoff = (100-82.5)/2 = 8.75

 

So make a Array 11x11 using the lower left XY point eg 8.75,8.75

Posted
15 hours ago, BIGAL said:

Its not rocket science an example

 

L=100

Max offset = 10

X space = 7.5

100-2xoff = 80

80/ 7.5 = 10.666666

round up to 11

100-11*7.5 = 82.5

Xoff = (100-82.5)/2 = 8.75

 

So make a Array 11x11 using the lower left XY point eg 8.75,8.75

That or use an array.

  • 10 months later...
Posted

Ok the easy answer is get bounding box of shape pick a control point then array say your circle covering the complete area contained by the bounding box, then you get all the circles inside the pline put on another layer, isolate the original dummy layer and delete all circles. Turn on your circle layer and all done.

 

image.png.03f6667a5ab5a842f9d720e4110deb15.png

 

Yes I have something but need what it is you are really trying to end up with. Post a dwg

 

Posted (edited)

spacer.png

 

; POINTGRID - 2023.08.17 exceed
; https://www.cadtutor.net/forum/topic/76068-point-grid-by-selecting-polyline/?do=findComment&comment=622077
; Make point grid in closed polyline or circle.
; command : POINTGRID
; 1. Select objects to use as boundary.
; 2. Enter the x, y spacing gap value between each point.
; 3. If you want to give a margin to the inside of the boundary object, enter an offset value. 
;    (Enter the space bar if not necessary.)
; This code modifies PDMODE and PDSIZE variable for visibility. you can modify it to you want.

(defun c:POINTGRID ( / ss x_gap y_gap base_offset ssl index ent obj minpt maxpt x_dist y_dist x_count y_count x_val y_val x_return pt_val judge point_output )
  (vl-load-com)
  (princ "\n pick boundary polyline : ")
  (setq ss (ssget))
  (setq x_gap (abs (getreal "\n input x gap : ")))
  (setq y_gap (abs (getreal "\n input y gap : ")))
  (setvar 'pdmode 33)
  (setvar 'pdsize (/ (min x_gap y_gap) 5))
  (setq base_offset (getreal "\n input inside offset (if required) : "))
  (if (= base_offset nil) (setq base_offset 0) (setq base_offset (abs base_offset)))
  (setq ssl (sslength ss))
  (setq ss2 (ssadd))
  (setq index 0)
  (repeat ssl
    (setq ent (ssname ss index))
    (if (> base_offset 0)
      (progn 
        (setq obj (EX:InsideOffsetOnce (vlax-ename->vla-object ent) base_offset))
      )
      (setq obj (vlax-ename->vla-object ent))
    )
    (vla-GetBoundingBox obj 'minpt 'maxpt)
    (setq minpt (vlax-safearray->list minpt))
    (setq maxpt (vlax-safearray->list maxpt))
    (setq x_dist (- (- (car maxpt) (car minpt)) base_offset))
    (setq y_dist (- (- (cadr maxpt) (cadr minpt)) base_offset))
    (setq x_count (fix (/ x_dist x_gap)))
    (setq y_count (fix (/ y_dist y_gap)))
    (setq x_val (+ (car minpt) base_offset))
    (setq x_return x_val)
    (setq y_val (+ (cadr minpt) base_offset))
    (repeat (+ y_count 1)
      (repeat (+ x_count 1)
        (setq pt_val (list x_val y_val))
        (if (setq judge (@cv_inside pt_val (vlax-vla-object->ename obj) 1))
          (progn
            ;(princ "\n ")
            ;(princ judge)
            ;(princ pt_val)
            ;(princ " : it's inside")
            ;(setq circletest (entmakex (list '(0 . "CIRCLE") (cons 10 pt_val) (cons 62 8) (cons 40 (/ (min x_gap y_gap) 5)))))
            (setq point_output (entmakex (list (cons 0 "POINT") (cons 100 "AcDbEntity") (cons 67 0) (cons 100 "AcDbPoint") (cons 10 pt_val ) (cons 50 0))))
            (setq ss2 (ssadd point_output ss2))
          )
          (progn
            ;(princ "\n ")
            ;(princ judge)
            ;(princ pt_val)
            ;(princ " : it's not inside")
          )
        )
        (setq x_val (+ x_val x_gap))
      )
      (setq x_val x_return)
      (setq y_val (+ y_val y_gap))
    )
    (if (> base_offset 0)
      (vla-delete obj)
    )
    (setq index (+ index 1))
  )
  (princ "\n complete")
  (redraw)
  (sssetfirst nil ss2)
  (princ)
)

; EX:InsideOffsetOnce - 2023.08.01 exceed
; Inside Offsets the "obj" object entered as an argument inward by "offdis" numeric value.
(defun EX:InsideOffsetOnce ( obj offdis / offsetobj subloop1 subloop2 subloop1type subloop2type subloop1length subloop2length looplength ) 
  (if (vlax-method-applicable-p obj 'offset)
    (progn
      (setq subloop1 (car (vlax-safearray->list (vlax-variant-value (vlax-invoke-method obj 'Offset (* offdis 1))))))
      (setq subloop2 (car (vlax-safearray->list (vlax-variant-value (vlax-invoke-method obj 'Offset (* offdis -1))))))
      (setq subloop1type (vlax-get-property subloop1 'ObjectName))
      (setq subloop2type (vlax-get-property subloop2 'ObjectName))
      (cond 
        ((= subloop1type "AcDbPolyline") (setq subloop1length (vlax-get-property subloop1 'length)))
        ((= subloop1type "AcDbCircle") (setq subloop1length (vlax-get-property subloop1 'Circumference)))
        ((= subloop1type "AcDbArc") (setq subloop1length (vlax-get-property subloop1 'Radius)))
      )
      (cond 
        ((= subloop2type "AcDbPolyline") (setq subloop2length (vlax-get-property subloop2 'length)))
        ((= subloop2type "AcDbCircle") (setq subloop2length (vlax-get-property subloop2 'Circumference)))
        ((= subloop2type "AcDbArc") (setq subloop2length (vlax-get-property subloop2 'Radius)))
      )
      (cond 
        ((> subloop1length subloop2length) (vla-delete subloop1) (setq offsetobj subloop2))
        ((< subloop1length subloop2length) (vla-delete subloop2) (setq offsetobj subloop1))
        ((= subloop1length subloop2length) (vla-delete subloop2) (setq offsetobj subloop1))
      )
      offsetobj
    )
    (progn
      (princ "\n This Object Cannot be Offset")
    )
  )
)


; Joe Burke - https://www.theswamp.org/index.php?topic=7785.msg98782#msg98782
(defun @cv_inside (PIQ Object Draw / IsPolyline Closest Start End Param P ClosestParam
                                     NextParam a1 a2 Defl @2D @Insect @Bulge @Deflect
                                     @Closest Color)
  ;;               "LOOK, MA'... NO RAYS!"
  ;; @Inside.lsp v1.0 (09-15-03) John F. Uhden, Cadlantic.
  ;; v2.0 Revised (09-17-03) - See notes below.
  ;; v3.0 Revised (09-20-03) - See notes below.
  ;; v4.0 Revised (09-20-04) but still missing something
  ;; v5.0 Revised (04-04-04) - See notes below.
  ;; Function to determine whether a point is inside the boundary
  ;; of a closed curve.
  ;; It employs the theorem that the sum of the deflections of a
  ;; point inside the curve should equal 360°, and if outside 0°
  ;; (both absolute values).
  ;;
  ;; Arguments:
  ;;   PIQ    - Point to test (2D or 3D point as a list in UCS)
  ;;   Object - Curve to test (Ename or VLA-Object)
  ;;   Draw   - Option to draw vectors to sample points, nil or non-nil
  ;;
  ;; Returns:
  ;;   T   (if the PIQ is inside the curve)
  ;;   nil (if either the arguments are invalid,
  ;;       or the PIQ is on or outside the curve)
  ;;
  ;; NOTES:
  ;;   Requires one or another version of the @delta function,
  ;;     such as included here.
  ;;   It will not work well with self-intersecting (overlapping)
  ;;     bulged polyline segments.
  ;;   Curves can be CIRCLEs, ELLIPSEs, LWPOLYLINEs, POLYLINES,
  ;;     SPLINEs, and maybe even more.
  ;;   Since all the calulations are based on angles relative to the
  ;;     current UCS, there shouldn't be any limitation caused by differences
  ;;     in elevation, but it is not suited for abnormal extrusion directions.
  ;;   (09-17-03) Found that cusps brought back inside the figure
  ;;     yield a total deflection of (* pi 2), so changed evaluation
  ;;     to see if deflection was greater than 4, which is
  ;;     equivalent to a fuzz factor of 2.28 from (* pi 2).
  ;;   (09-20-03) Found that bulged polyline segments needed special
  ;;     attention to determine the closest point to any segment because
  ;;     it might not be the closest point to the object, but must be
  ;;     evaluated to sample sufficient points.
  ;;   (04-04-04) Renamed to original @cv_Inside.lsp (c. 2002)
  ;;     Remembered there was an issue with splines, so included is a
  ;;     Closest evaluation, and a small sample increment, Though I still
  ;;     don't trust the results when the PIQ is near a sharp curve.  If splines
  ;;     important then make the sample rate tighter at the expense of speed.
  ;;     For polylines, the sample increment just 1.0 as there is a special
  ;;     subfunction to pick up the midpoint and closest point of bulged segments.
  ;;     For objects such as circles and ellipses the sample increment should be
  ;;     a multiple of pi to achieve a total deflection that is a multiple of pi
  ;;     with in a small fuzz factor.
  ;;     Yes, circles and ellipses can be evaluated more easily by a simple
  ;;     comparison of distances to their center, but this function is
  ;;     intended to treat them as just another curve and to demonstrate
  ;;     the method of using curve parameters and deflections.
  (vl-load-com)
  ;; Subunction to determine the deflection angle in radians beween two given angles
  (or (= (type @delta) 'SUBR)
    (defun @delta (a1 a2)
      (cond
        ((> a1 (+ a2 pi))
          (+ a2 pi pi (- a1))
        )
        ((> a2 (+ a1 pi))
          (- a2 a1 pi pi)
        )
        (1 (- a2 a1))
      )
    )
  )
  ;; Subfunction to convert a 3D point into 2D for the purpose
  ;; of ignoring the Z value.
  ;; Added (09-20-03)
  (defun @2D (p)(list (car p)(cadr p)))
  ;;--------------------------------------------------------
  ;; Subfunction to determine if an angle is with the sector
  ;; defined by two other angles.
  (defun @Insect (Ang Ba Ea)
    (if (> Ba Ea)
      (cond
        ((>= Ang Ba))
        ((<= Ang Ea))
        (1 nil)
      )
      (< Ba Ang Ea)
    )
  )
  ;; Subfunction to find the closest point to an object from a given point,
  ;; adjusted for elevation differences.  Input and output are in UCS
  (defun @Closest (P / P1 P2)
    (setq P (trans P 1 0)
          P2 P
    )
    (while (not (equal P1 P2 1e-10))
      (setq P1 P2
            P2 (vlax-curve-GetClosestPointTo Object P)
            P (list (car P)(cadr P)(last P2))
      )
    )
    (trans P2 0 1)
  )
  ;; Subfunction to emulate the GetBulge method, which can be used only
  ;; for simple polylines, not for fit-curved or splined.
  ;; Its dual purpose here is to find a point on a bulged segment closest to
  ;; the PIQ if it is within the bulge's sector and/or the midpoint of
  ;; the bulged segment, and to compute deflections to same in ascending
  ;; parameter order.
  (defun @Bulge (Param / V1 V2 P1 P2 Center Ba Ea Ma MidParam Delta Radius Swap Ang P)
    (and ;; once again the Koster approach
      (< Param End)
      (setq Param (fix Param))
      (setq MidParam (+ Param 0.5))
      (setq V1 (vlax-curve-getpointatparam Object Param))
      (setq V2 (vlax-curve-getpointatparam Object MidParam))
      (setq Ba (apply 'atan (reverse (@2d (vlax-curve-getSecondDeriv Object Param)))))
      (setq Ea (apply 'atan (reverse (@2d (vlax-curve-getSecondDeriv Object MidParam)))))
      (not (equal Ba Ea 1e-8))
      (setq P1 (polar V1 Ba 1.0))
      (setq P2 (polar V2 Ea 1.0))
      (setq Center (inters V1 P1 V2 P2 nil))
      (setq Radius (distance Center V1))
      (setq Ba (angle Center V1)) ; Beginning angle
      (setq V2 (vlax-curve-getpointatparam Object (1+ Param)))
      (setq Ea (angle Center V2)) ; End angle
      (setq Ma (angle Center (vlax-curve-getpointatparam Object MidParam))) ; Mid angle
      (setq MidP (trans (vlax-curve-GetPointAtParam Object MidParam) 0 1))
      ;; Since we don't have the value of bulge, and since the internal angle (Delta)
      ;; can be > pi, cut the segment in half and add up the separate deflections:
      (setq Delta (+ (@delta Ba Ma)(@delta Ma Ea)))
      ;; If you had a Tan function, then you could
      ;; (setq Bulge (Tan (/ Delta 4)))
      (or
        (> Delta 0)
        (setq Swap Ba Ba Ea Ea Swap)
      )
      (setq Ang (angle Center (trans PIQ 1 0)))
      (if (@Insect Ang Ba Ea)
        (setq P (trans (polar Center Ang Radius) 0 1)
              P (@Closest P)
              PParam (vlax-curve-GetParamAtPoint Object (trans P 1 0))
        )
      )
      (cond
        ((or (not PParam)(= PParam MidParam))
          (@Deflect MidP 3) ; in UCS
        )
        ((< PParam MidParam)
          (@Deflect P 1) ; in UCS
          (@Deflect MidP 3) ; in UCS
        )
        ((> PParam MidParam)
          (@Deflect MidP 3) ; in UCS
          (@Deflect P 1) ; in UCS
        )
      )
    )
  )
  (defun @Deflect (P Color)
    (setq a2   (angle PIQ P) ; in UCS
          Defl (+ Defl (@delta a1 a2))
          a1 a2
    )
    ;(if Draw (grdraw PIQ P Color))
  )
  ;;=========================================================
  ;; Begin input validation and processing using the
  ;; Steph(and) Koster approach which simply stops evaluating
  ;; on any nil result:
  (and
    ;; Validate input object:
    (cond
      ((not Object)
        (prompt "  No object provided.")
      )
      ((= (type Object) 'VLA-Object))
      ((= (type Object) 'Ename)
        (setq Object (vlax-ename->vla-object Object))
      )
      (1 (prompt "  Improper object type."))
    )
    ;; Validate input point:
    (or
      (and
        (< 1 (vl-list-length PIQ) 4)
        (vl-every 'numberp PIQ)
      )
      (prompt " Improper point value.")
    )
    ;; Validate that object is a curve:
    (or
      (not
        (vl-catch-all-error-p
          (setq Start
            (vl-catch-all-apply
              'vlax-curve-getStartPoint
              (list Object)
            )
          )
        )
      )
      (prompt "  Object is not a curve.")
    )
    ;; Validate that curve is closed:
    (or
      (equal Start (vlax-curve-getendpoint Object) 1e-10)
      (prompt "  Curve is not closed.")
    )
    (setq Closest (@Closest PIQ)) ; in UCS
    ;; Test to see if PIQ is on object:
    (not (equal (@2D PIQ)(@2D Closest) 1e-10)) ; in WCS
    (setq ClosestParam (vlax-curve-getparamatpoint Object (trans Closest 1 0)))
    (or (not Draw) (not (grdraw PIQ Closest 2)))
    (setq IsPolyline (wcmatch (vla-get-objectname Object) "*Polyline")
          End (vlax-curve-getEndparam Object)
    )
    ;; Set the sample rates based on object type and end parameter.
    (cond
      (IsPolyline
        (setq ClosestParam nil)
        (setq Sample 1.0)
      )
      ((equal (rem End pi) 0.0 1e-10)
        (setq Sample (* pi 0.2))
      )
      ((setq Sample (* End 0.01)))
    )
    ;; Initialize the values to be incremented and computed:
    (setq Param Sample Defl 0.0)
    (setq a1 (angle PIQ (trans Start 0 1))) ; in UCS
    ;; Iterate through the object by parameter:
    (while (<= Param End)
      (setq Param (min Param End))
      ;; This little extra makes sure not to skip an angle
      ;; that might throw off the total deflection.
      ;; It is at the top of while loop in case ClosestParam
      ;; is less than the first sample.
      ;; This is not to be used with polylines.
      (if (and ClosestParam (> Param ClosestParam))
        (setq P Closest
              ClosestParam nil
              NextParam Param
              Color 2
        )
        (setq P (trans (vlax-curve-getpointatparam Object Param) 0 1)
              NextParam (+ Param Sample)
              Color 3
        )
      )
      (@Deflect P Color) ; in UCS
      ;; For polylines check for additional points on any
      ;; bulged segment.
      (if IsPolyline (@Bulge Param))
      (setq Param NextParam)
    )
    ;(if Draw (print Defl)) ; Optional display of results
    (> (abs Defl) 4) ; to allow for rough calculations if
                     ; sample rates are too high (large).
  )
)

 

Edited by exceed
  • Like 1
  • Thanks 1
Posted

i posted this a few days ago. just take out the boundary command stuff.

 

 

Posted

It worked perfectly @exceed Thank you very much !
Thank you very much to those who comment.

  • Like 1
  • 4 months later...
Posted
On 17.08.2023 at 04:14, exceed said:
; POINTGRID - 2023.08.17 exceed  

@exceed very good code,

you can make a pointgrid in a staggered order (in chess)

here is an excerpt of the code, maybe it will help?

(if is_chess
                (setq sm (/ dy 2.0))
                (setq sm 0)
            ) ;_ end of if
            (if (setq lstVer (ru-pline-make-any-contour Header t NIL))
                (progn
                    (setq contour_ent (entlast))


 

is_chess.png

Posted
1 hour ago, BIGAL said:

Use the same idea of overfilling shape then delete circles on outside.

But this is not at all suitable for my task.
I need to get a point grid in a staggered order...

Posted (edited)

Sorry wrong zigzag posted up dated above, uses multi getvals.lsp for value entry.

 

 

 

Edited by BIGAL
Posted (edited)
6 hours ago, BIGAL said:

uses multi getvals.lsp for value entry

This command suggests creating an array specifying the step and quantity (not in staggered order).
This is easier to do in AutoCAD.
But I need to fill the contours with a staggered array, by type lisp POINTGRID @exceed...

Image 1.png

Edited by Nikon

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