TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jmcshane on June 19, 2013, 07:33:37 AM

Title: Civil 3D Structure Position
Post by: jmcshane on June 19, 2013, 07:33:37 AM
Hi,
This might sound like a silly question, but how do I find the insertion point of a civil 3d Structure.
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 Objectctr (1+ Objectctr))
)
)
  )
How do I extract the xyz from this line!
Code: [Select]
(setq StructurePos (vla-get-position Item))
Sorry if its obvious, I can't see the wood from the trees here!

Cheers

John
Title: Re: Civil 3D Structure Position
Post by: ronjonp on June 19, 2013, 09:36:56 AM
Just a stab in the dark .. but maybe ..


Code: [Select]
(setq StructurePos (vlax-get Item 'position))
Title: Re: Civil 3D Structure Position
Post by: CAB on June 19, 2013, 09:39:36 AM
I would guess InsertionPoint  8)
Title: Re: Civil 3D Structure Position
Post by: jmcshane on June 19, 2013, 09:53:23 AM
Hi Ronjonp,

Your code gives me this line.
Code: [Select]
#<VLA-OBJECT IAeccPoint3d 000000005d92b4d0>
And when I inspect it using the vlide editor it shows me the x y z coordinates but I cant seem to "catch" them.


CAB,
I have tried that as well but it doesn't recognize insertionpoint.

John
I am wondering if it is available at all seeing as it is a civil 3d object! :-(
Thanks for the replies.
Title: Re: Civil 3D Structure Position
Post by: ronjonp on June 19, 2013, 10:12:44 AM
Maybe?


Code: [Select]
(list (vlax-get structurepos 'x) (vlax-get structurepos 'y) (vlax-get structurepos 'z))
Title: Re: Civil 3D Structure Position
Post by: jmcshane on June 19, 2013, 10:22:08 AM
Bingo! :-)
Thanks Ronjonp.
Title: Re: Civil 3D Structure Position
Post by: dgorsman on June 19, 2013, 10:23:58 AM
In otherwords, the X Y and Z are properties of the IAeccPoint3D object.  They can be accessed via the property functions such as (vlax-get...) and (vlax-get-property...).  This can be applied to virtually any object.
Title: Re: Civil 3D Structure Position
Post by: jmcshane on June 19, 2013, 10:45:11 AM
Thanks dgorsman, so much to learn....so little time!!
But that is definitely something I will be looking in to.
Title: Re: Civil 3D Structure Position
Post by: ronjonp on June 19, 2013, 10:49:59 AM
Bingo! :-)
Thanks Ronjonp.


Happy to help :).


This would probably work too:


Code: [Select]
(list (vla-get-x structurepos) (vla-get-y structurepos) (vla-get-z structurepos))
Title: Re: Civil 3D Structure Position
Post by: alanjt on June 19, 2013, 01:11:32 PM
Cool!


Code: [Select]
(defun _structurePosition (structure / p)
  (setq p (vlax-get structure 'Position))
  (mapcar 'vlax-get (list p p p) '(x y z))
)

Code: [Select]
(defun _pipeStartEndStructurePosition (pipe / lst)
  (if (vl-remove nil
                 (setq lst (mapcar
                             (function
                               (lambda (structure / s p)
                                 (if (and (setq s (vlax-get pipe structure))
                                          (setq p (vlax-get s 'Position))
                                     )
                                   (mapcar 'vlax-get (list p p p) '(x y z))
                                 )
                               )
                             )
                             '(StartStructure EndStructure)
                           )
                 )
      )
    lst
  )
)
Title: Re: Civil 3D Structure Position
Post by: jmcshane on June 20, 2013, 06:12:27 AM
 :-o

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


John

Title: Re: Civil 3D Structure Position
Post by: jmcshane on June 20, 2013, 08:01:07 AM
Just before I break something here, Can someone please enlighten me as to why this line doesn't select text at the given coordinate?

Code: [Select]
(setq TextSel
(ssget "X"
(list (0 . "TEXT")
      (cons 10
    (list (vlax-get structurepos 'x)
  (vlax-get structurepos 'y)
    )
      )
)
)
  )
I have spend all morning on this and time has run out to get this routine finished.  :-(
Any help would be appreciated.
John
Title: Re: Civil 3D Structure Position
Post by: Lee Mac on June 20, 2013, 08:14:27 AM
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (setq TextSel
  2.     (ssget "_X"
  3.         (list '(0 . "TEXT")
  4.             (list 10 (vlax-get structurepos 'x) (vlax-get structurepos 'y) 0.0)
  5.         )
  6.     )
  7. )

PS: Please avoid using tabs in code, they are annoying  :-P
Title: Re: Civil 3D Structure Position
Post by: Lee Mac on June 20, 2013, 08:20:35 AM
Code: [Select]
(defun _pipeStartEndStructurePosition (pipe / lst)
...
)

Nice code, but no need for the if statement:
Code - Auto/Visual Lisp: [Select]
  1. (defun _pipestartendstructureposition ( obj )
  2.     (vl-remove nil
  3.         (mapcar
  4.             (function
  5.                 (lambda ( prop / str pos )
  6.                     (if
  7.                         (and
  8.                             (setq str (vlax-get obj prop))
  9.                             (setq pos (vlax-get str 'position))
  10.                         )
  11.                         (mapcar '(lambda ( p ) (vlax-get pos p)) '(x y z))
  12.                     )
  13.                 )
  14.             )
  15.            '(startstructure endstructure)
  16.         )
  17.     )
  18. )
Title: Re: Civil 3D Structure Position
Post by: alanjt on June 20, 2013, 08:27:42 AM
Code: [Select]
(defun _pipeStartEndStructurePosition (pipe / lst)
...
)

Nice code, but no need for the if statement:
Code - Auto/Visual Lisp: [Select]
  1. (defun _pipestartendstructureposition ( obj )
  2.     (vl-remove nil
  3.         (mapcar
  4.             (function
  5.                 (lambda ( prop / str pos )
  6.                     (if
  7.                         (and
  8.                             (setq str (vlax-get obj prop))
  9.                             (setq pos (vlax-get str 'position))
  10.                         )
  11.                         (mapcar '(lambda ( p ) (vlax-get pos p)) '(x y z))
  12.                     )
  13.                 )
  14.             )
  15.            '(startstructure endstructure)
  16.         )
  17.     )
  18. )
If you notice, the vl-remove nil was only a check, I don't store it. I want it to return a nil value for the start/end structure. That way, I know which one is missing and which is there.
eg.
(nil <point>) => no start, only end
(<point nil)   => no end, only start
nil                 => a pipe without a structure.
Title: Re: Civil 3D Structure Position
Post by: alanjt 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>)
Title: Re: Civil 3D Structure Position
Post by: alanjt 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
  )
)
Title: Re: Civil 3D Structure Position
Post by: jmcshane 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
Title: Re: Civil 3D Structure Position
Post by: Lee Mac 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. )
Title: Re: Civil 3D Structure Position
Post by: alanjt 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):
Title: Re: Civil 3D Structure Position
Post by: jmcshane 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
Title: Re: Civil 3D Structure Position
Post by: alanjt 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.
Title: Re: Civil 3D Structure Position
Post by: jmcshane 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
Title: Re: Civil 3D Structure Position
Post by: alanjt 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. :)