Convert polyline to 2Dpolyline

Convert polyline to 2Dpolyline

eakos1
Advocate Advocate
600 Views
3 Replies
Message 1 of 4

Convert polyline to 2Dpolyline

eakos1
Advocate
Advocate

Hello, 

 

I've created a program which works with 2dPolylines. 

It reads and print the point of vertexes, the bulge and the radius of the arcs. If the radius one arcs are smaller then 3 the width of this segment will be set up to 1. Program running fine. 

But I wanted to work it with polylines too. So I've jut added the convertpoly command. (command "convertpoly" "h" name_Poly "")

The conversation is working but after that the program stops at the second vertex with failure: error: Automation Error. Invalid class

 

And intresting, in one drawing I have 4 polylines, buy one it is not working but by the other three it is working. 

If I create a polyline with arcs in it it works. But if I make a copy and convert it back to polyline again than I get error. 

 

What can be the problem?  Why the result is not stable?

 

eakos1_0-1621891622622.png

 

(defun c:coord (/ width name_Poly e obj element r bulge p1 p2 L r angARC segmentIndex)

   (vl-load-com)
   (setq width 1)   ;width o the arc segments in the polyline

   -------------------------------------------------------------------------------------------

   (setq name_Poly (car (entsel)))
   (setq e (entget name_Poly))

   (if (= (cdr (assoc 0 e)) "LWPOLYLINE")
      (progn
	 (command "pedit" name_Poly "w" "0" "" "")
	 (command "convertpoly" "h" name_Poly "")
	 (princ "\nPolyline converted into 2Dpolyline")
	 (setq e (entget name_Poly))
      )		    ;end progn
   )		    ;end if
  
		    ;get the parent entity list
   (setq obj (vlax-ename->vla-object name_Poly))
		    ; (vlax-dump-object obj T)
   (setq segmentIndex -1)
   (setq element (fix (+ 1 (vlax-curve-getEndParam obj)))) ;ennyi vertexből áll a ployline

   -------------------------------------------------------------------------------------------

   (repeat element

      (setq segmentIndex (1+ segmentIndex))
      (setq e (entget (entnext (cdr (car e)))))
		    ;get the vertex entity list
      (if (/= (cdr (assoc 0 e)) "SEQEND")
		    ;if it is not "end-of-sequence
	 (progn
		    ;do the following
	    (terpri)
		    ;new line

	    (setq p1 (cdr (assoc 10 e)))
	    (setq bulge (cdr (assoc 42 e)))

	    (princ p1)

		    ;print the co-ordinates
	    (princ (strcat " bulge = " (rtos bulge)))
		    ;print the bulge

	    (if	(/= bulge 0)
	       (progn
		  (setq p2 (cdr (assoc 10 (entget (entnext (cdr (car e)))))))
		  (setq L (distance p1 p2))
		  (setq angARC (* 4.0 (atan bulge)))
		  (setq r (abs (/ (/ L 2) (sin (/ angARC 2.0)))))
		  (princ (strcat " r = " (rtos r)))

		  (if (< r 2.99999)
		     (vla-setwidth obj segmentIndex width width)
		     (vla-setwidth obj segmentIndex 0 0)

		  ) ;end if
		    ;If radius small then change the width
	       )    ;end progn
	    )	    ;end if
	 )	    ;progn
      )		    ;if
   )		    ;repeat
   (princ)
)		    ;defun

 

0 Likes
Accepted solutions (1)
601 Views
3 Replies
Replies (3)
Message 2 of 4

ronjonp
Advisor
Advisor
Accepted solution

Maybe this? No need to convert.

(defun c:coord (/ angarc bulge element l name_poly obj p1 p2 r segmentindex width)
  (vl-load-com)
  (setq width 1)			;width o the arc segments in the polyline
  (if (and (setq name_poly (car (entsel))))
    (progn
      (setq element (fix (vlax-curve-getendparam name_poly))) ;ennyi vertexbol áll a ployline
      (setq segmentindex -1)
      (setq obj (vlax-ename->vla-object name_poly))
      ;; 
      (repeat element
	(print (setq p1 (vlax-curve-getpointatparam name_poly (setq segmentindex (1+ segmentindex))))
	)
	(setq bulge (vla-getbulge (vlax-ename->vla-object name_poly) segmentindex))
					;print the co-ordinates
	(princ (strcat " bulge = " (rtos bulge))) ;print the bulge
	(if (/= bulge 0)
	  (progn (setq p2 (vlax-curve-getpointatparam name_poly (1+ segmentindex)))
		 (setq l (distance p1 p2))
		 (setq angarc (* 4.0 (atan bulge)))
		 (setq r (abs (/ (/ l 2) (sin (/ angarc 2.0)))))
		 (princ (strcat " r = " (rtos r)))
		 (if (< r i-e3)
		   (vla-setwidth obj segmentindex width width)
		   (vla-setwidth obj segmentindex 0 0)
		 )			;end if
					;If radius small then change the width
	  )				;end progn
	)				;end if
      )
    )
  )					;progn
  (princ)
)					;defun
Message 3 of 4

eakos1
Advocate
Advocate

Execept one mistake it works fine 🙂 Thank you. 

 

I had to correct this one:

(if (< r i-e3) --> (if (< r 3)

 

It was just a type failure? I guess yes, or somehting that I don't konw. 

0 Likes
Message 4 of 4

ronjonp
Advisor
Advisor

@eakos1 wrote:

Execept one mistake it works fine 🙂 Thank you. 

 

I had to correct this one:

(if (< r i-e3) --> (if (< r 3)

 

It was just a type failure? I guess yes, or somehting that I don't konw. 


Glad it worked for you .. that was a typo for sure 😳

0 Likes