TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CHulse on January 27, 2023, 12:28:01 PM

Title: User defined properties of C3D cogo points
Post by: CHulse on January 27, 2023, 12:28:01 PM
Hi
I'm trying to extract some user defined property (UDP) values from Civil3D cogo point entities and something is baffling me.

I'm able to get the UDP values successfully using this:
Code - Auto/Visual Lisp: [Select]
  1. (vlax-invoke x 'GetUserDefinedPropertyValue "UDP_tag")

But if I try to make a separate function and pass the same variables to it, it fails for me.  I'm probably doing something stupid and I'm hoping y'all will set me straight.
This fails:
Code - Auto/Visual Lisp: [Select]
  1. (defun _GetCogoUDP (cogo UDP / )
  2.   (vlax-invoke cogo 'GetUserDefinedPropertyValue UDP))

example call:
Code - Auto/Visual Lisp: [Select]
  1. (_GetCogoUDP x "UDP_Tag")

Any help would be much appreciated.
Title: Re: User defined properties of C3D cogo points
Post by: Jeff_M on January 27, 2023, 01:29:17 PM
Cary, UDPs are case-sensitive, so "UDP_tag" is not the same as "UDP_Tag"
Title: Re: User defined properties of C3D cogo points
Post by: CHulse on January 27, 2023, 02:09:09 PM
Cary, UDPs are case-sensitive, so "UDP_tag" is not the same as "UDP_Tag"

Thanks for catching that. That's just a generic example, but it made me go back to check and I did indeed have a typo. Thank you.

To take this further - can you suggest how best to trap an error like that?

Thanks!
Title: Re: User defined properties of C3D cogo points
Post by: Jeff_M on January 27, 2023, 03:25:14 PM
Since there is no way with the COM API to get the UDP Classifications in the drawing without finding those assigned to point groups, this is how I'd do it:
Code - Auto/Visual Lisp: [Select]
  1. (defun _GetCogoUDP (cogo UDP / )
  2.   (if (FindUDP UDP (vlax-get cogo 'Document))
  3.     (setq return (vlax-invoke cogo 'GetUserDefinedPropertyValue UDP))
  4.     (setq return "UDP not found.")
  5.     )
  6.   return
  7.   )
  8.  
  9. (defun FindUDP (UDPName civdoc / )
  10.   (setq retval nil
  11.         way nil)
  12.   (vlax-for grp (vlax-get civdoc 'pointgroups)
  13.     (if (setq udpclass (vlax-invoke grp 'getuserdefinedpropertyclassification 'way))
  14.       (vlax-for udp (vlax-get udpclass 'userdefinedproperties)
  15.         (if (= UDPName (vlax-get udp 'name))
  16.           (setq retval udp)
  17.           )
  18.         )
  19.       )
  20.     )
  21.   retval
  22.   )
Title: Re: User defined properties of C3D cogo points
Post by: CHulse on January 27, 2023, 03:55:29 PM
Thanks Jeff

Though when I implement that, it returns "UDP not found." regardless, for both valid and invalid UDP names?
Title: Re: User defined properties of C3D cogo points
Post by: CHulse on January 27, 2023, 04:10:26 PM
So this is what I came up with to avoid the error. Seems to work.

Code - Auto/Visual Lisp: [Select]
  1. (defun _GetCogoUDP (cogo UDP / u ret)
  2. (setq u (vl-catch-all-apply 'vlax-invoke (list cogo 'GetUserDefinedPropertyValue UDP)))
  3.         (setq ret "UPD Not Found")
  4.         (setq ret u)
  5.   )
  6. ret
  7. );_end defun
Title: Re: User defined properties of C3D cogo points
Post by: Jeff_M on January 27, 2023, 04:30:37 PM
The FindUDP worked for me. It will fail if no point groups have the Classification assigned, or if it is assigned with multiple classifications.

After I posted that I thought about trying the vl-catch-all-apply approach. Glad it worked for you.
Title: Re: User defined properties of C3D cogo points
Post by: CHulse on January 27, 2023, 04:32:47 PM
Ah. I think all my point groups are set to "ALL" for the classification.
So that I think explains it?
Title: Re: User defined properties of C3D cogo points
Post by: Jeff_M on January 27, 2023, 05:08:31 PM
Yes, the All would cause no UDPs to be found with the method I posted. The COM API really sucks for working with UDPs and UDP Classifications. It is good at some things, but is really limited.
Title: Re: User defined properties of C3D cogo points
Post by: CHulse on January 28, 2023, 08:10:57 AM
Yes, the All would cause no UDPs to be found with the method I posted. The COM API really sucks for working with UDPs and UDP Classifications. It is good at some things, but is really limited.

Thanks again Jeff. Very helpful.
Title: Re: User defined properties of C3D cogo points
Post by: CHulse on July 28, 2023, 09:23:25 AM
Circling back to this - is there any way to assign a UDP Classification to a point group via lisp?
Title: Re: User defined properties of C3D cogo points
Post by: Jeff_M on July 28, 2023, 11:26:26 AM
Circling back to this - is there any way to assign a UDP Classification to a point group via lisp?
Yes. http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/com/AeccXLandLib__IAeccPointGroup__SetUserDefinedPropertyClassification@[in]_AeccUDPClassificationApplyWay@[in]_VARIANT.htm

(vlax-invoke ptgroup 'setuserdefinedpropertyclassification 2 "StationOffset");;2=custom classification, 0=None, 1=All
Title: Re: User defined properties of C3D cogo points
Post by: CHulse on July 28, 2023, 12:47:29 PM
Thanks Jeff