Author Topic: Civil 3D Structure Position  (Read 9048 times)

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Civil 3D Structure Position
« Reply #15 on: June 20, 2013, 08:32:34 AM »
:-o

Alan, you are confusing me! :-)
I am so out of practice!
How would I use this?


John
The first can be applied to a vla-object for a structure and it will return the position. The second can be applied to a vla-object pipe and it will return the positions of the start and end (if any) structures.

Code: [Select]
(_structurePosition <vla-object>)
(_pipeStartEndStructurePosition <vla-object>)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Civil 3D Structure Position
« Reply #16 on: June 20, 2013, 08:42:15 AM »
Perhaps this would be better:


Code: [Select]
(defun _pipeStartEndStructurePosition (pipe / lst)
  (if (vl-some 'and
               (setq lst (mapcar
                           (function
                             (lambda (structure / s p)
                               (if (setq s (vlax-get pipe structure))
                                 (mapcar 'vlax-get (list (setq p (vlax-get s 'Position)) p p) '(x y z))
                               )
                             )
                           )
                           '(StartStructure EndStructure)
                         )
               )
      )
    lst
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

jmcshane

  • Newt
  • Posts: 83
Re: Civil 3D Structure Position
« Reply #17 on: June 20, 2013, 09:05:52 AM »
PS: Please avoid using tabs in code, they are annoying  :-P
I hear you, but I have just got 2014 and haven't had time to set things up properly.

Quote
Code: [Select]
    (setq TextSel
       (ssget "_X"
           (list '(0 . "TEXT")
               (list 10 (vlax-get structurepos 'x) (vlax-get structurepos 'y) 0.0)
           )
       )
    )
Thanks Lee, but this is still not working!

Here is the deal....
I have a civil 3d Model, I also have a piece of text at the insertion of each Structure which needs to become the structure name.........
I am trying to catch each piece of text at each Structure insertion point and rename the structure.

My code:
Code: [Select]
(if (> (setq SelectionSet (ssget "X" (list (cons 0 "AECC_STRUCTURE"))))
         Nil
         )
    (progn
      (setq Objectctr 0)
      (repeat (sslength SelectionSet)
        (setq Item (ssname SelectionSet Objectctr))
        (setq Item (vlax-ename->vla-object Item))
        (setq StructureName (vla-get-name Item))
        (setq StructurePos (vla-get-position Item))
        (setq StructureIns
               (list (vlax-get structurepos 'x)
                     (vlax-get structurepos 'y)
                     (vlax-get structurepos 'z)
                     )
              )
        (progn
          (setq TextSel (ssget "_X"
                               (list '(0 . "TEXT")
                                     (list 10
                                           (vlax-get structurepos 'x)
                                           (vlax-get structurepos 'y)
                                           0.0
                                           )
                                     )
                               )
                )
          (if TextSel
            (repeat (setq Ctr (sslength TextSel))
              (setq Ctr (1- Ctr))
              (setq TextItem (ssname TextSel Ctr))
              (setq TextItem (vlax-ename->vla-object TextItem))
              (if (= (vlax-safearray->list
                       (vlax-variant-value
                         (vla-get-insertionpoint TextItem)
                         )
                       )
                     (list (car StructureIns) (cadr StructureIns) 0.0)
                     )
                (setq TextString (vla-get-TextString TextItem))
                )
              )
            )
          )
        (vla-put-name Item TextString)
        (setq Objectctr (1+ Objectctr))
        )
      )
    )

Can anyone help?

Thanks in advance.

John
John.

Civil 3D 2021. Windows 10

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Civil 3D Structure Position
« Reply #18 on: June 20, 2013, 09:25:11 AM »
Perhaps the filter needs some tolerance:

Code - Auto/Visual Lisp: [Select]
  1. (if (setq ss1 (ssget "_X" '((0 . "AECC_STRUCTURE"))))
  2.     (repeat (setq idx (sslength ss1))
  3.         (setq obj (vlax-ename->vla-object (ssname ss1 (setq idx (1- idx))))
  4.               pos (vla-get-position obj)
  5.               ins (mapcar '(lambda ( p ) (vlax-get pos p)) '(x y z))
  6.         )
  7.         (if (setq ss2
  8.                 (ssget "_X"
  9.                     (list
  10.                        '(0  . "TEXT")
  11.                        '(-4 . ">=,*") (vl-list* 10 (- (car ins) 1e-3) (cdr ins))
  12.                        '(-4 . "<=,*") (vl-list* 10 (+ (car ins) 1e-3) (cdr ins))
  13.                        '(-4 . "*,>=") (vl-list* 10 (car ins) (- (cadr ins) 1e-3) (cddr ins))
  14.                        '(-4 . "*,<=") (vl-list* 10 (car ins) (+ (cadr ins) 1e-3) (cddr ins))
  15.                     )
  16.                 )
  17.             )
  18.             (vla-put-name obj (vla-get-textstring (vlax-ename->vla-object (ssname ss2 0))))
  19.         )
  20.     )
  21. )

Or maybe we need to test DXF Group 11 in case the Text is not left-justified:

Code - Auto/Visual Lisp: [Select]
  1. (if (setq ss1 (ssget "_X" '((0 . "AECC_STRUCTURE"))))
  2.     (repeat (setq idx (sslength ss1))
  3.         (setq obj (vlax-ename->vla-object (ssname ss1 (setq idx (1- idx))))
  4.               pos (vla-get-position obj)
  5.               ins (mapcar '(lambda ( p ) (vlax-get pos p)) '(x y))
  6.               pt1 (mapcar '+ ins '(1e-3 1e-3))
  7.               pt2 (mapcar '- ins '(1e-3 1e-3))
  8.         )
  9.         (if (setq ss2
  10.                 (ssget "_X"
  11.                     (list
  12.                        '(0  . "TEXT")
  13.                        '(-4 . "<OR")
  14.                            '(-4 . "<AND")
  15.                                '(-4 . ">=,*") (list 10 (car pt2) 0.0)
  16.                                '(-4 . "<=,*") (list 10 (car pt1) 0.0)
  17.                                '(-4 . "*,>=") (list 10 0.0 (cadr pt2))
  18.                                '(-4 . "*,<=") (list 10 0.0 (cadr pt1))
  19.                            '(-4 . "AND>")
  20.                            '(-4 . "<AND")
  21.                                '(-4 . ">=,*") (list 11 (car pt2) 0.0)
  22.                                '(-4 . "<=,*") (list 11 (car pt1) 0.0)
  23.                                '(-4 . "*,>=") (list 11 0.0 (cadr pt2))
  24.                                '(-4 . "*,<=") (list 11 0.0 (cadr pt1))
  25.                            '(-4 . "AND>")
  26.                        '(-4 . "OR>")
  27.                     )
  28.                 )
  29.             )
  30.             (vla-put-name obj (vla-get-textstring (vlax-ename->vla-object (ssname ss2 0))))
  31.         )
  32.     )
  33. )
« Last Edit: June 20, 2013, 09:29:55 AM by Lee Mac »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Civil 3D Structure Position
« Reply #19 on: June 20, 2013, 09:35:42 AM »
PS: Please avoid using tabs in code, they are annoying  :-P
I hear you, but I have just got 2014 and haven't had time to set things up properly.

Quote
Code: [Select]
    (setq TextSel
       (ssget "_X"
           (list '(0 . "TEXT")
               (list 10 (vlax-get structurepos 'x) (vlax-get structurepos 'y) 0.0)
           )
       )
    )
Thanks Lee, but this is still not working!

Here is the deal....
I have a civil 3d Model, I also have a piece of text at the insertion of each Structure which needs to become the structure name.........
I am trying to catch each piece of text at each Structure insertion point and rename the structure.

My code:
Code: [Select]
(if (> (setq SelectionSet (ssget "X" (list (cons 0 "AECC_STRUCTURE"))))
         Nil
         )
    (progn
      (setq Objectctr 0)
      (repeat (sslength SelectionSet)
        (setq Item (ssname SelectionSet Objectctr))
        (setq Item (vlax-ename->vla-object Item))
        (setq StructureName (vla-get-name Item))
        (setq StructurePos (vla-get-position Item))
        (setq StructureIns
               (list (vlax-get structurepos 'x)
                     (vlax-get structurepos 'y)
                     (vlax-get structurepos 'z)
                     )
              )
        (progn
          (setq TextSel (ssget "_X"
                               (list '(0 . "TEXT")
                                     (list 10
                                           (vlax-get structurepos 'x)
                                           (vlax-get structurepos 'y)
                                           0.0
                                           )
                                     )
                               )
                )
          (if TextSel
            (repeat (setq Ctr (sslength TextSel))
              (setq Ctr (1- Ctr))
              (setq TextItem (ssname TextSel Ctr))
              (setq TextItem (vlax-ename->vla-object TextItem))
              (if (= (vlax-safearray->list
                       (vlax-variant-value
                         (vla-get-insertionpoint TextItem)
                         )
                       )
                     (list (car StructureIns) (cadr StructureIns) 0.0)
                     )
                (setq TextString (vla-get-TextString TextItem))
                )
              )
            )
          )
        (vla-put-name Item TextString)
        (setq Objectctr (1+ Objectctr))
        )
      )
    )

Can anyone help?

Thanks in advance.

John
Why don't you just use a structure label that only displays the name? Wouldn't that be easier, or am I missing something?

Here's what I use (see attached):
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

jmcshane

  • Newt
  • Posts: 83
Re: Civil 3D Structure Position
« Reply #20 on: June 20, 2013, 10:07:21 AM »
Thanks Lee,
Tolerance................ Something I am short off, but what the code needed!!!
Turns out, the text was not exactly on the insert of the structure.


Alan,
That is all we use as well!

Thanks for all your help guys.

John
John.

Civil 3D 2021. Windows 10

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Civil 3D Structure Position
« Reply #21 on: June 20, 2013, 11:42:20 AM »
Thanks Lee,
Tolerance................ Something I am short off, but what the code needed!!!
Turns out, the text was not exactly on the insert of the structure.


Alan,
That is all we use as well!

Thanks for all your help guys.

John
I wonder if you could have used ssget crossing from the structure's bounding box.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

jmcshane

  • Newt
  • Posts: 83
Re: Civil 3D Structure Position
« Reply #22 on: June 20, 2013, 12:08:07 PM »
That is a good idea Alan, even with Lee's code I still had a fair bit of manual cleaning to do as it didn't catch all the text. Then there was the issue of duplicate numbers. ( its a complicated system!!)
Unfortunately I am going to have to leave it until I have to do it again or until I get free time, as I now have to rename all the associated alignments!! :-)

Thanks for your help.

John
John.

Civil 3D 2021. Windows 10

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Civil 3D Structure Position
« Reply #23 on: June 20, 2013, 12:18:25 PM »
That is a good idea Alan, even with Lee's code I still had a fair bit of manual cleaning to do as it didn't catch all the text. Then there was the issue of duplicate numbers. ( its a complicated system!!)
Unfortunately I am going to have to leave it until I have to do it again or until I get free time, as I now have to rename all the associated alignments!! :-)

Thanks for your help.

John
Sounds like you have your work cut out for you. Good luck. :)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox