Author Topic: Civilsurface getpoint?  (Read 8189 times)

0 Members and 1 Guest are viewing this topic.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Civilsurface getpoint?
« on: June 26, 2013, 02:09:47 AM »
Hello!

In the image you can see if I move mouse cursor arround surfaces in Civil3d I get show hight from it. My question is: can I have value via vla-object och entmake some textentity ?

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Civilsurface getpoint?
« Reply #1 on: June 26, 2013, 03:27:19 AM »
Very good question, but I'd say no. Very few of the vertical products (C3D included) allow working with their objects through VLA/DXF. You might get lucky if it could be seen programmatically as a surface - in which case such Z value can be calculated mathematically. I don't have C3D so I can't test this for you.

Alternatively, does C3D have something like a spot-dimension? I know I can do such in Revit on a topo-surface. If C3D can do such, you could place such dim temporarily and then obtain its value. Or perhaps some other idea which can be placed onto the surface, perhaps some "hosted" entity / something which can be cut on that surface?

Otherwise, I guess your best bet would be to try getting this property from DotNet. Though it seems even DotNet only just starting to get decent C3D capabilities: http://civilizeddevelopment.typepad.com/
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Civilsurface getpoint?
« Reply #2 on: June 26, 2013, 04:54:36 AM »
Hi Irne!

Yes I think too thereīs no way getting around dotNET. Revit is not the same as Civil but I could be parallels each other. If you talking about surfaces in Revit maybe it could be the same Iīm talking about surfaces in Civil.
ActiveX have a small choice from Civilobject for example parametic parameters in dynamic blocks. However how do I know which ActiveX have ?
Have it a library I can looking for ?


Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Civilsurface getpoint?
« Reply #3 on: June 26, 2013, 10:02:31 AM »
You can do this with ActiveX in lisp:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq surfss (ssget ":S" '((0 . "AECC_*SURFACE"))))
  2.   (progn
  3.     (setq surf (vlax-ename->vla-object (ssname surfss 0)))
  4.     (while (setq pt (getpoint "\nPick point within surface boundary: "))
  5.       (setq elev (vlax-invoke surf 'findelevationatxy (car pt) (cadr pt)))
  6.       ;;...do what you need with the elevation value
  7.       )
  8.     )
  9.   )
It will error if the pt is not within the surface so be sure to add an error handler.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Civilsurface getpoint?
« Reply #4 on: June 26, 2013, 01:53:44 PM »
Playing around...

Code: [Select]
(defun _surfaceElevationAtPoint (point / i n x s e p f)
  (if (and (vl-consp point)
           (setq i -1
                 n (trans (getvar 'VSMIN) 0 1)
                 x (trans (getvar 'VSMAX) 0 1)
                 s (ssget "_C" (list (car n) (cadr n)) (list (car x) (cadr x)) '((0 . "AECC_*SURFACE")))
           )
      )
    (while (and (not f) (setq e (ssname s (setq i (1+ i)))))
      (if (not (vl-catch-all-error-p
                 (setq p (vl-catch-all-apply
                           'vlax-invoke
                           (list (vlax-ename->vla-object e)
                                 'FindElevationAtXY
                                 (car point)
                                 (cadr point)
                           )
                         )
                 )
               )
          )
        (setq f p)
      )
    )
  )
  f
)


*giggle* inxs
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Civilsurface getpoint?
« Reply #5 on: June 28, 2013, 09:41:11 AM »
Thank you for playing :-D exellent done...

two questions:
- Can I read an surface which is in bakground as Civil shortcut
- what happens if I have two surfaces above each other

I have no example to can test it, but
(vlax-get-property (vlax-ename->vla-object e) 'DisplayName)
gives me the surface there I generate a surfacepoint

Is it opportunity to select a surface with ActiveX?


irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Civilsurface getpoint?
« Reply #6 on: June 29, 2013, 02:04:47 AM »
- what happens if I have two surfaces above each other

I have no example to can test it, but
(vlax-get-property (vlax-ename->vla-object e) 'DisplayName)
gives me the surface there I generate a surfacepoint

Is it opportunity to select a surface with ActiveX?
Isn't the (vlax-ename->vla-object e) already "selecting"the entity in ActiveX? The e being the ename of the surface object.

You could "select" direct through ActiveX too. Though it's not as straight-forward as the ssget function: http://entercad.ru/acadauto.en/index.html?page=idh_selectionsets.htm and http://entercad.ru/acadauto.en/index.html?page=idh_selectionset_object.htm
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Civilsurface getpoint?
« Reply #7 on: June 29, 2013, 02:56:25 AM »
Ah yeah Irne, thats was it.
Can I ask you - Iīm new in VBA-API, the help links you paste in. How can I find equal Visual Lisp methode if I find for example how definition a VBA object from selectionset.

SelectionSets Property
Signature
object.SelectionSets
VBA class name:   AcadDatabasePreferences

it means okay VBA interpreter have the object selectionset. But where I can find equal vla-functions ?
Do you work with Apropos- in vlide-editor ?

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Civilsurface getpoint?
« Reply #8 on: June 29, 2013, 12:02:27 PM »
Unfortunately there's no such thing. Even the old VLisp help only showed how to translate from the VBA code to VLA.

Basically there are 3 ways from VL into ActiveX:
  • Originally the vlax-invoke / vlax-get / vlax-put. These came from the original Vital Lisp extension to ACad r14.
  • Similar are vlax-invoke-method / vlax-get-property / vlax-put-property. Though these do not do automatic conversions between lisp/ActiveX data types.
  • Then most methods / properties also get "shortcut" functions. E.g. (vlax-invoke <object> 'Item <index>) could be re-written as (vla-Item <object> <index>)
The main principle of ActiveX is that it's object oriented. So for anything you want it to do (method), or value you want to obtain (property get) or value you want to set (property set) you first need its owner object. In VBA it would be the usual OOP syntax with dot-notation:
Code: [Select]
ObjectReference.MethodName(Arg1, Arg2, ... ArgN) 'For calling a method
variable = ObjectReference.MethodName(Arg1, Arg2, ... ArgN) 'For calling a method and setting its result into a variable
variable = ObjectReference.PropertyName 'For setting the value of a property into a variable
ObjectReference.PropertyName = variable 'For setting the value in a variable into the property
The same code can be written in these 3 ways in VLisp
Code - Auto/Visual Lisp: [Select]
  1. ;; Using the old Vital Lisp functions
  2. (vlax-invoke ObjectReference 'MethodName Arg1 Arg2 ... ArgN) ;For calling a method
  3. (setq variable (vlax-invoke ObjectReference 'MethodName Arg1 Arg2 ... ArgN) ;For calling a method and setting its result into a variable
  4. (setq variable (vlax-get ObjectReference 'PropertyName)) ;For setting the value of a property into a variable
  5. (vlax-put ObjectReference 'PropertyName variable) ;For setting the value in a variable into the property
  6.  
  7. ;; Using the new Visual Lisp functions
  8. (vlax-invoke-method ObjectReference 'MethodName Arg1 Arg2 ... ArgN) ;For calling a method
  9. (setq variable (vlax-invoke-method ObjectReference 'MethodName Arg1 Arg2 ... ArgN) ;For calling a method and setting its result into a variable
  10. (setq variable (vlax-get-property ObjectReference 'PropertyName)) ;For setting the value of a property into a variable
  11. (vlax-put-property ObjectReference 'PropertyName variable) ;For setting the value in a variable into the property
  12.  
  13. ;; Using the shortcut Visual Lisp functions (if they exist)
  14. (vla-MethodName ObjectReference Arg1 Arg2 ... ArgN) ;For calling a method
  15. (setq variable (vla-MethodName ObjectReference Arg1 Arg2 ... ArgN) ;For calling a method and setting its result into a variable
  16. (setq variable (vla-get-PropertyName ObjectReference)) ;For setting the value of a property into a variable
  17. (vla-put-PropertyName ObjectReference variable) ;For setting the value in a variable into the property
So you see all except for the shortcuts are directly translatable from the VBA code. You add the vlax-[invoke/get/set][-method/property] function before, then remove the VBA parentheses, commas & dots, wrapping the whole in lisp parentheses and quoting the Method/Property name.

In the shortcut the Method/Property name moves into the function name itself.

Edit: renamed the set to put ... sorry about that.
« Last Edit: June 29, 2013, 12:13:03 PM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Civilsurface getpoint?
« Reply #9 on: June 30, 2013, 03:12:07 AM »
Nice insight in functionally Vlisp, you gave me a great first lesson.

Jeff and Alan gaves me example to can get properties of getting point on a surface. How did they know which properties haves vla-oject AcadSurface. If I look in explanation to AcadSurface (vla-object AcadSurface) I find this (image). How can I get information to the line especially what is "function" 'findelevationatxy and what did it need. I donīt get it, but I would like know where I can read, what it means

Code: [Select]
(setq elev (vlax-invoke surf 'findelevationatxy (car pt) (cadr pt)))

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Civilsurface getpoint?
« Reply #10 on: June 30, 2013, 06:14:34 AM »
You can try the vlax-dump-object function which lists the properties & methods acad knows about the object you send it. It prints these (together with a little info about each) to the text screen. Unfortunately it doesn't always show everything.

You might also be able to get to them using MP's tool here: http://www.theswamp.org/index.php?topic=19890.25
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Civilsurface getpoint?
« Reply #11 on: June 30, 2013, 11:15:08 AM »
Jeff and Alan gaves me example to can get properties of getting point on a surface. How did they know which properties haves vla-oject AcadSurface. If I look in explanation to AcadSurface (vla-object AcadSurface) I find this (image). How can I get information to the line especially what is "function" 'findelevationatxy and what did it need. I donīt get it, but I would like know where I can read, what it means
You found the Help for an AcadSurface which is not the same as the AeccTinSurface or AeccSurface. You can find the help files for the Civil COM  (ActiveX) libraries HERE

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Civilsurface getpoint?
« Reply #12 on: July 03, 2013, 04:26:03 AM »
Okay, I come a bit forward. I was continueing with Alans code, exspecially how it works with selectionset and viewWindow (very intresting done!). If I have a very small windowsView I canīt see all surfaces in position of mouse cursor, because surface boundary goes over the windowsView from selectionset.
The attached image in my first thread view Civil rollover tooltips, that is not catch with Lisp or?

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Civilsurface getpoint?
« Reply #13 on: July 03, 2013, 02:20:12 PM »
Code: [Select]
(defun c:SEI (/ ss i o surfaces pt elev lst)
  ;; Surface Elevation Inquiry
  ;; Extract elevation from point in Civil 3D surface(s)
  ;; Alan J. Thompson, 05.25.10 / 2013.07.03 (rewrite)

  (if (setq ss (ssget "_A" '((0 . "AECC_*SURFACE"))))
    (repeat (setq i (sslength ss))
      (setq o (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
      (if (not (eq (vla-get-stylename o) "_No Display"))
        (setq surfaces (cons (cons (vla-get-name o) o) surfaces))
      )
    )
  )

  (if (null surfaces)
    (alert "No visible surface in drawing.")
    (while (setq lst nil
                 pt  (getpoint "\nSpecify point on surface: ")
           )
      (setq pt (trans pt 1 0))
      (foreach surface (vl-sort surfaces (function (lambda (a b) (> (car a) (car b)))))
        (if (not (vl-catch-all-error-p
                   (setq elev (vl-catch-all-apply
                                'vlax-invoke
                                (list (cdr surface) 'FindElevationAtXY (car pt) (cadr pt))
                              )
                   )
                 )
            )
          (setq lst (cons " "
                          (cons "(\""
                                (cons (car surface)
                                      (cons "\" ~ " (cons (rtos elev) (cons ")" lst)))
                                )
                          )
                    )
          )
        )
      )
      (if lst
        (princ (apply 'strcat (cons "\n" (cdr lst))))
        (princ "\nPoint outside of surface.")
      )
    )
  )
  (princ)
)
(vl-load-com)
(princ)
« Last Edit: July 04, 2013, 10:02:35 AM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Civilsurface getpoint?
« Reply #14 on: July 04, 2013, 04:24:15 AM »
Hi Alan!

Thank you for your fantastic work youīve done. Iīm so happy it works perfect. I must testing little more, how it works - doesnīt have much experience with surface-vla-objects.