Jump to content

Recommended Posts

Posted (edited)

I have a lisp routine that works some of the time but the results are not the same every time, looking for some help.

 

You select an edge that you want divided up with marks at a certain interval and select which side of the edge to draw the marks on. sometimes it puts the marks on the correct side but other times it is a mirror opposite of the side selected.

image.thumb.png.c161c884066ed879d6ad29ed4af4fae5.png

 

 

 

(defun C:STEPMARKINGS (/ *Error* )
  (while (/= (setq EDGEOFTREAD (car (entsel "\nSelect the edge of the piece where the markings will be added."))) nil)
    ;(setq EDGEOFTREAD (car (entsel "\nSelect the edge of the piece where the markings will be added.")))
    (while (= EDGEOFTREAD nil)
			  (alert "Nothing selected. Select the edge of the piece where the markings will be added.")
			  (setq EDGEOFTREAD (car (entsel "\nSelect the edge of the piece where the markings will be added.")))
	  )
    (setq OPOINT (getpoint "\nSelect a point inside the piece: "))
    (command "offset" "1" EDGEOFTREAD OPOINT "")
    (setq TREADOFFSET (entlast))
    (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"ARC")
      (setq Enttype "ARC")
      ()
    )
    (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"LINE")
      (setq Enttype "LINE")
      ()
    )
    (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"LWPOLYLINE")
      (setq Enttype "LWPOLYLINE")
      ()
    )
    (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"SPLINE")
      (setq Enttype "SPLINE")
      ()
    )
    (cond
	    ((= Enttype "ARC")
		   ;(alert "The entity you selected is an ARC");used only for diagnostics
        (setq EDGEOFTREADSTART (vlax-get(vlax-ename->vla-object EDGEOFTREAD) "startpoint"))
        (setq EDGEOFTREADEND (vlax-get(vlax-ename->vla-object EDGEOFTREAD) "endpoint"))
        (setq TREADOFFSETSTART (vlax-get(vlax-ename->vla-object TREADOFFSET) "startpoint"))
        (setq TREADOFFSETEND (vlax-get(vlax-ename->vla-object TREADOFFSET) "endpoint"))
	    )
	    ((= Enttype "LINE")
		    ;(alert "The entity you selected is a LINE");used only for diagnostics
        (setq EDGEOFTREADSTART (vlax-get(vlax-ename->vla-object EDGEOFTREAD) "startpoint"))
        (setq EDGEOFTREADEND (vlax-get(vlax-ename->vla-object EDGEOFTREAD) "endpoint"))
        (setq TREADOFFSETSTART (vlax-get(vlax-ename->vla-object TREADOFFSET) "startpoint"))
        (setq TREADOFFSETEND (vlax-get(vlax-ename->vla-object TREADOFFSET) "endpoint"))
	    )
      ((= Enttype "LWPOLYLINE")
		    ;(alert "The entity you selected is a POLYLINE");used only for diagnostics
        (setq EDGEOFTREADSTART (vlax-curve-getstartpoint EDGEOFTREAD))
        (setq EDGEOFTREADEND (vlax-curve-getEndPoint EDGEOFTREAD))
        (setq TREADOFFSETSTART (vlax-curve-getstartpoint TREADOFFSET))
        (setq TREADOFFSETEND (vlax-curve-getEndPoint TREADOFFSET))
	    )
      ((= Enttype "SPLINE")
		    ;(alert "The entity you selected is a SPLINE");used only for diagnostics
        (setq EDGEOFTREADSTART (vlax-curve-getstartpoint EDGEOFTREAD))
        (setq EDGEOFTREADEND (vlax-curve-getEndPoint EDGEOFTREAD))
        (setq TREADOFFSETSTART (vlax-curve-getstartpoint TREADOFFSET))
        (setq TREADOFFSETEND (vlax-curve-getEndPoint TREADOFFSET))
	    )
    )
    (command "line" EDGEOFTREADSTART TREADOFFSETSTART "")
    (setq MARKING (entlast))
    (command "chprop" MARKING "" "LA" "InkMark" "")
    (command "ERASE" TREADOFFSET "")
    (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"ARC")
      (setq Enttype "ARC")
      ()
    )
    (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"LINE")
      (setq Enttype "LINE")
      ()
    )
    (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"LWPOLYLINE")
      (setq Enttype "LWPOLYLINE")
      ()
  )
    (if (eq (cdr(assoc 0 (entget EDGEOFTREAD)))"SPLINE")
      (setq Enttype "SPLINE")
      ()
    )
    (cond
	    ((= Enttype "ARC")
		    ;(alert "The entity you selected is an ARC");used only for diagnostics
        (vl-load-com)
        (setq TREADLEN (vla-get-arclength (vlax-ename->vla-object EDGEOFTREAD)))
	    )
	    ((= Enttype "LINE")
		    ;(alert "The entity you selected is a LINE");used only for diagnostics
        (vl-load-com)
        (setq TREADLEN (vla-get-length (vlax-ename->vla-object EDGEOFTREAD)))
	    )
      ((= Enttype "LWPOLYLINE")
		    ;(alert "The entity you selected is a POLYLINE");used only for diagnostics
        (vl-load-com)
        (setq TREADLEN (vla-get-length (vlax-ename->vla-object EDGEOFTREAD)))
	    )
      ((= Enttype "SPLINE")
		    ;(alert "The entity you selected is a SPLINE");used only for diagnostics
        (vl-load-com)
        (setq EDGEOFTREADVL (vlax-ename->vla-object EDGEOFTREAD))
        (setq TREADLEN (vlax-curve-getDistAtPoint EDGEOFTREADVL (vlax-curve-getEndPoint EDGEOFTREADVL)))
	    )
    )
	(setq TREADLENFEET (/ TREADLEN 12))
  (setq MARKNUMROUGH (/ TREADLENFEET 2 ))
  (setq MARKNUMROUND (fix (+ MARKNUMROUGH (if (minusp MARKNUMROUGH) -0.5 0.5))))
  (setq MARKNUM (+ MARKNUMROUND 2))
  (cond
    ((<= TREADLENFEET 8)
    (setq MARKNUM 5)
    )
  )
  
  (initcommandversion)
  (command ".ARRAYPATH" MARKING "" EDGEOFTREAD "AS" "N" "M" "D" "I" MARKNUM "X")
  (setq LASTMARK (entlast))
    (command "ERASE" LASTMARK MARKING "")
  )
(princ "Marking Complete")
)
(defun *Error* ( msg )
 	(setq ORIGINALERROR *Error*)
	(setq *Error* ORIGINALERROR)
	(alert "There was an error. If you pressed escape to exit the routine, just press OK to close this box, and re-run this routine.")
 	(princ "ERROR: You either pressed escape or something didnt work. Try again.")
  (command "ERASE" MARKING)
  (setvar 'qaflags 0)
(princ msg)
)

 

Edited by EricDevault
Posted (edited)

.The code seems to work fine
You should attach an example drawing

Edited by GLAVCVS
Posted
  On 1/30/2025 at 6:19 PM, GLAVCVS said:

.The code seems to work fine
You should attach an example drawing

I have a drawing attached. And the odd thing is it works sometimes and sometimes not. It is also random on which machine it works on

Drawing 3.dwgFetching info...

Posted

If its pline/lines then i would have a good guess at Clockwise v's anti clockwise, it will make stuff go inside or out depending on direction, simple to check for. Also for plines need to use which segment selected not just pt1->pt2 etc. 

 

(defun getplineseg ( / elst ename pt param preparam postparam)
  (setq elst (entsel "\nSelect pline segment: "))
  (setq ename (car elst))
  (setq pt (cadr elst))
  (setq pt (vlax-curve-getClosestPointTo ename pt))
  (print (setq param (vlax-curve-getParamAtPoint ename pt)) )
  (print (setq preparam (fix param)) )
  (print (setq postparam (1+ preparam)) )
  (setq pt1 (vlax-curve-getPointAtParam ename preparam)
  pt2 (vlax-curve-getPointAtParam ename postparam))
)

 

Posted

The options specified in your code calling the 'arraypath' command do not seem to match those that appear in my version of AutoCAD.
Could you explain each of them?

Posted
  On 1/31/2025 at 7:37 AM, GLAVCVS said:

The options specified in your code calling the 'arraypath' command do not seem to match those that appear in my version of AutoCAD.
Could you explain each of them?

These are the arguments for the standard command line arraypath, see the call (initcommandversion). If you initialize arraypath through lisp it is a different set of arguments that is why I stuck with the command version

Posted
  On 1/31/2025 at 7:29 AM, BIGAL said:

If its pline/lines then i would have a good guess at Clockwise v's anti clockwise, it will make stuff go inside or out depending on direction, simple to check for. Also for plines need to use which segment selected not just pt1->pt2 etc. 

 

(defun getplineseg ( / elst ename pt param preparam postparam)
  (setq elst (entsel "\nSelect pline segment: "))
  (setq ename (car elst))
  (setq pt (cadr elst))
  (setq pt (vlax-curve-getClosestPointTo ename pt))
  (print (setq param (vlax-curve-getParamAtPoint ename pt)) )
  (print (setq preparam (fix param)) )
  (print (setq postparam (1+ preparam)) )
  (setq pt1 (vlax-curve-getPointAtParam ename preparam)
  pt2 (vlax-curve-getPointAtParam ename postparam))
)

 

Expand  

The objects in the example drawing are either lines or arcs.

Can you tell me more about clockwise v anti? Does that mean the way the lines and arcs were drawn? Or the orientation of start point and end point? How would I check for that?

Posted

Easy for lines or plines you pick an end when selecting this implies the start point. You compare the distance to the two ends and flip the pts if necessary. Minimal testing with arcs.

 

(defun swapends (ent / obj)
 (setq pt3 (cadr ent))
 (setq obj (vlax-ename->vla-object (car ent)))
 (setq start (vlax-curve-getstartPoint obj))
 (setq end (vlax-curve-getEndPoint obj))
 (setq d1 (distance pt3 end))
 (setq d2 (distance pt3 start))
 (if (< d1 d2)
  (progn
  (setq temp end)
  (setq end start)
  (setq start temp)
 )
)
(princ)
)

 

  • Like 1
Posted (edited)
  On 2/1/2025 at 10:21 PM, BIGAL said:

Easy for lines or plines you pick an end when selecting this implies the start point. You compare the distance to the two ends and flip the pts if necessary. Minimal testing with arcs.

 

(defun swapends (ent / obj)
 (setq pt3 (cadr ent))
 (setq obj (vlax-ename->vla-object (car ent)))
 (setq start (vlax-curve-getstartPoint obj))
 (setq end (vlax-curve-getEndPoint obj))
 (setq d1 (distance pt3 end))
 (setq d2 (distance pt3 start))
 (if (< d1 d2)
  (progn
  (setq temp end)
  (setq end start)
  (setq start temp)
 )
)
(princ)
)

 

Expand  

I get this error on the first line (setq pt3 (cadr ent))

error: bad argument type: consp <Entity name: 2838a47c390>

I get that error no matter if line or arc

Edited by EricDevault
Typo
Posted

Look at pt3 CADR. When you use Entsel  the CAR of the value returned is the entity name, the CADR is the point that was used to pick the entity.

  • Like 1
Posted
  On 2/6/2025 at 9:56 PM, BIGAL said:

Look at pt3 CADR. When you use Entsel  the CAR of the value returned is the entity name, the CADR is the point that was used to pick the entity.

I am really struggling to implement this into my code in the first post. Any pointers? I am also trying to relearn LISP from a long hiatus...

Posted

Further testing shows that if the X of the path is a negative number then the array path command gets all glitchy and does not provide the intended results from just command line entry. However, if I move all of my pieces to the positive side of X axis then it "mostly" works. 

At this point I am looking for suggestions to move away from the array path command. 

 

I need a 1" line(blue line in pic) aligned along a path(arc or line) at maximum 2' intervals. The line must be on the inside of the "piece"(white lines in pic). The pieces are closed polygons but not closed in regards to poly lines and they will not be poly lines.

 

image.png.9b84f863ac0f1dd93dc75833f74cd593.png

Posted (edited)

Ok a couple of answers no code at moment for a point on your plines shape you can get the 90 angle of that point so draw the little 1 unit line in correct direction. 

 

Clue 2 if the shapes are closed plines then you need to work on a pline segment not pts, Lee-Mac has a pline properties program that looks at BULGES that is what a curved section of a pline is known as so its is easy once you know the length of the arc and the start point of the arc to work out the pts along it. So need code like that to work out for say a picked segment is it a straight line or curved. 

 

Clue 3 can check the length of the segment so if less than a value don't add ticks.

 

Need something like a list the U shape (100 675 100 575) , 1/2 pie (500 750)

 

Will have a think, some one else may jump in 1st.

 

 

Edited by BIGAL
  • 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...