Just notes from Opie A commentary on AutoCAD and Civil 3d

Retrieve COGO Point Object

Usually, when attempting to modify objects within drawings, one must ensure the object exists within the drawing. If the object doesn’t exist, but code attempts to modify it, your code will probably not complete as expected.

Today’s code does just that for Civil 3D point objects.

Using the code I previously posted to retrieve the current Civil 3D drawing document allows us to retrieve the Point Collection. We can then query the collection with the supplied point ID. The result of that query would return the existing point object or nil for non-existing point ids.

Get Point Object

(defun OP:GetPoint (iPointID / oPoint cPoints)
  ;|

OP_GetPoint_1_0.lsp

Version History
1.0.1         October 24, 2017 Initial Release

Dependencies: OP:c3ddoc
              http://justopie.github.io/blog/2016/01/how-to-add-a-point-group-with-autolisp/#c3ddoc
Usage:        (OP:GetPoint)
Arguments:    iPointID
  Type:       Integer or String
Returns:      AECCPoint object or nil

Copyright © 2017 by Richard Lawrence
|;
  (if (and (op:c3ddoc)
	   (setq cPoints (vlax-get-property _C3DDoc 'Points))
	   (not	(vl-catch-all-error-p
		  (setq	oPoint (vl-catch-all-apply
				 'vlax-invoke-method
				 (list cPoints 'find iPointID)
			       )
		  )
		)
	   )
      )
    oPoint
  )
)
Select all

This is intended as a sub-routine. One would need to supply the point id to this routine as an integer or string.

If you have suggestions to improve this code, leave a comment below.

If you liked this post, you can share it with your followers or follow me on Twitter!

Similar Posts