Jump to content

Forward Visibility Lisp - DXF issue


Recommended Posts

Posted

Hi I found this Forward Visibility Lips online but it was drawing the forward vis line slightly wrong so I have modified it now. It works okay, but when I was debugging it at the end of the routine it would through an error message (See image). The lisp however does complete everything as required apart from setting Layer 0 at the end. I am looking to address that error.

image.png.741970adb51a34d922f60b3b1e3b7e07.png

(vl-load-com)
(defun C:CTS-ForwardVis ()
	;Set the Layer for the New Polylines
  (if (not (tblsearch "LAYER" "CTS-Forward Visibility")) 
    (command "-LAYER" "_M" "CTS-Forward Visibility" "_C" "True" "255,100,0" "CTS-Forward Visibility" "" ""))
  (command "clayer" "" "CTS-Forward Visibility" "")
  
  ; Predefined variables
  (setq ForwardVisDistance 15.0)    ; Default forward visibility distance
  (setq inc 2.0)        ; Default increment/resolution
  
  ; Prompt user to accept/change defaults
  (initget "Yes No")
  (if (= (getkword (strcat "\nUse default settings? [Yes/No] <Yes>: ")) "No")
    (progn
      (setq ForwardVisDistance (getdist (strcat "\nEnter default visibility distance <" (rtos ForwardVisDistance 2 2) ">: ")))
      (setq inc (getdist (strcat "\nEnter default increment/resolution <" (rtos inc 2 2) ">: ")))
    )
  )
  
  (princ (strcat"\nSelect Polyline:"))
	(while
		(not
			(setq js
				(ssget "_+.:E:S" 
					(list
						(cons 0 "*POLYLINE,ARC,SPLINE")
						(cons 67 (if (eq (getvar "CVPORT") 2) 0 1))
						(cons 410 (if (eq (getvar "CVPORT") 2) "Model" (getvar "CTAB")))
						(cons -4 "<NOT")
							(cons -4 "&") (cons 70 112)
						(cons -4 "NOT>")
					)
				)
			)
		)
	)
  
  ;----- Assign the Selected Polyline to a VLA-Object and get its Length and other properties
	(setq
		SelPline (vlax-ename->vla-object (ssname js 0))
		SelPline_Length (vlax-curve-getDistAtParam SelPline (vlax-curve-getEndParam SelPline))
    Counter 0.0
    SPoint nil
    EPoint nil
  )
  
  ;----- Check Forward Visi Distance and Increment against the Length of the Selected Polyline
  (while (>= ForwardVisDistance SelPline_Length)
    (if (>= ForwardVisDistance SelPline_Length) (princ "\nDistance execeded length of Selected Polyline"))
  )
  (while (>= inc SelPline_Length)
    (if (>= inc SelPline_Length) (princ "\nDistance execeded length of Selected Polyline"))
  )
  
  ;----- Function to create Forward Visibility Polylines
	(while (< Counter SelPline_Length)
		(setq EPoint (vlax-curve-getPointAtDist SelPline (+ Counter ForwardVisDistance)))
    (setq SPoint (vlax-curve-getPointAtDist SelPline Counter))
    (entmake
      (append
        '(
          (0 . "LWPOLYLINE")
          (100 . "AcDbEntity")
          (67 . 0)
          (410 . "Model")
          (8 . "CTS-Forward Visibility")
          (62 . 256)
          (6 . "ByLayer")
          (370 . -2)
          (100 . "AcDbPolyline")
          (90 . 2)
        )
        (list (cons 10 SPoint))
        (list (cons 10 EPoint))
        '((210 0.0 0.0 1.0))
      )
    )
   
    (setq SPoint (vlax-curve-getPointAtDist SelPline (+ Counter inc)))
    (setq Counter (+ Counter inc))
	)
    (command "clayer" "" "0" "")
)

 

Thank you!!

Posted

Sounds like on the last run through the while loop SPoint is having an error... if you look at (setq SPoint (vlax-curve-getPointAtDist SelPline (+ Counter inc))) - do you need this line since at the start of the next loop you are setting SPoint again and before it is used.

  • Thanks 1
Posted

Hi

Like @Stevenp, I can't verify exactly what this is about either: I'm not in front of a PC. But it looks like the last SPoint is 'nil' because '(+ Counter ForwardVisDistance)' is a number greater than the length of 'selPline'.

There are a few lines of code that are unnecessary, but they don't prevent your routine from working, so just try changing
(while (< Counter SelPline_Length)
to

(while (and (setq EPoint (vlax-curve-getPointAtDist SelPline (+ Counter ForwardVisDistance))) (setq SPoint (vlax-curve-getPointAtDist SelPline Counter)))

 

It looks like you used AI to do this, but you should still be able to remove the excess code after making these changes.

 

  • Like 1
  • Thanks 1
Posted

Ignoring the code for the moment, "Civil Site Design" has check site lines and it checks against the terrain model and the vertical alignment, not just a 2D answer. Looks at the drivers eye height and target height which is part of the check for us here in AUS.

  • Like 1
Posted

I use this for layer 0 at the end of a LISP.

 

  (command "_.LAYER" "_Set" "0" "")

 

 

Error: Bad DXF group: (10) means that the application has attempted to create an entity with wrong vertices (a polyline with a single vertex, identical endpoints for a line, etc.).

 

https://www.cadforum.cz/en/error-bad-dxf-group-10-tip9081

 

I think you could be passing 2D points when a 3D points are expected, but I won't be able to take a better look until Monday sometime.

 

Most likely in the...

 

;----- Function to create Forward Visibility Polylines

 

 

P.S.

 

Just for the record, what exactly is this LISP supposed to do?

 

Can you post an example drawing?

 

P.S.S.

 

Quote

...I found this Forward Visibility Lips online but it was drawing the forward vis line slightly wrong so I have modified it now...

 

Do you have a link or a copy of the original LISP?

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