Jump to content

DXF group 10 only returning x and y values (not Z)


thebiglebowski

Recommended Posts

I am writing a routine that involves picking a point on a polyline, and reversing that polyline if the picked point does not match the start point.

For reasons unclear to me, when I pull the info for DXF group 10 from first entity in the polyline, it returns only x an y values, but not z. Can anybody tell me why?

 

The code I am using is below.

 

(while (setq strtpt (getpoint "\n Pick Starting Point(s) "))
    
	(setq tmppt (polar strtpt (dtr 45.0) 0.0001))
	(setq tmppt2 (polar strtpt (dtr 225.0) 0.0001))
   
	(setq profile(ssget "C" tmppt tmppt2 '((0 . "LWPOLYLINE")(70 . 0)(6 . "BYLAYER"))))  ;creates selection sets that filters out everything but open polylines - ignores non bylayer lines also

	(if (eq profile nil)		;If wrong type of ent it picked
		(princ "\n Invalid - Entity Must be an Open LWPOLYLINE, and Bylayer LT ")
	)


	;-----------------------------------------------------------------------------------------------------
	
	(if (and strtpt profile) ;everything after the above must have this qualifier to not error out
		(progn
		(setq entname (ssname profile 0))
		(setq entinfo (entget entname))   
		(setq firstpoint (cdr (assoc 10 entinfo)))

		(princ firstpoint)
		(if (/= strtpt firstpoint)
			(princ "\n Startpoint does not match first vertex - Reverse entity here")
		)

		) ;End PROG
	) ; End if
	
)

 

The returned values look like this

 

strtpt (34.7925 14.6191 0.0)

 

firstpoint (20.9037 6.86948)

 

And because of this these values always evaluate as not equal. Any input?

 

 

Link to comment
Share on other sites

Try this, lwpolylines return X & Y 3dlines 3dpolys return X&Y&Z

 


(while (setq strtpt (getpoint "\n Pick Starting Point(s) "))
(setq strpt (list (car strpt)(cadr strpt)))

Link to comment
Share on other sites

I would do following modifications... Just in case your LWPOLYLINE is in 3D SPACE oriented randomly...

 

(while (setq strtpt (trans (getpoint "\n Pick Starting Point(s) ") 1 0))

(setq profile (ssget "_C" (trans strtpt 0 1) (trans strtpt 0 1) (list '(0 . "LWPOLYLINE") '(-4 . "<or") '(70 . 0) '(70 . 128) '(-4 . "or>") '(6 . "BYLAYER"))))

(setq firstpoint (trans (list (car (cdr (assoc 10 entinfo))) (cadr (cdr (assoc 10 entinfo))) (cdr (assoc 38 entinfo))) entname 0))

(if (not (equal strtpt firstpoint 1e-6))
  (princ "\n Startpoint does not match first vertex - Reverse entity here")
)

 

Link to comment
Share on other sites

Since 2D Polylines (LWPOLYLINES) are planar objects, it is inefficient & wasteful to store the same Z-coordinate value alongside every vertex; therefore, each vertex is defined with an X & Y coordinate value, and the elevation of the polyline is stored against DXF group 38.

 

As such, to obtain the 3D OCS coordinates of the first vertex, you might use:

(append (cdr (assoc 10 entinfo)) (list (cdr (assoc 38 entinfo))))

However, where the comparison is concerned there are two issues:

  1. You should only use the '=' operator when comparing integers and strings - observe the following:
    _$ (= '(1) '(1))
    nil

    When comparing lists or doubles, you should use the equal function and, if such lists represent points, include a tolerance (which represents the distance between such points), e.g.

    _$ (equal '(1.0 2.0 3.0) '(1.0 2.0 3.0) 1e-8)
    T
  2. When comparing points, you should ensure that both points are defined relative to the same coordinate system. In your example, getpoint will return a point defined relative to the active UCS, and the vertices of LWPolylines are defined relative to the OCS; as such, you should transform the OCS vertex to be relative to the active UCS before comparing the two points:
    (equal strtpt (trans (append (cdr (assoc 10 entinfo)) (list (cdr (assoc 38 entinfo)))) (cdr (assoc 210 entinfo)) 1) 1e-8)

     

Edited by Lee Mac
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...