Author Topic: Zoom to a Pipe - Help  (Read 399 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2508
  • I can't remeber what I already asked! I need help!
Zoom to a Pipe - Help
« on: June 07, 2021, 10:27:56 AM »
Gotta question. I took the zoom to structure command and applied it to the pipe side of things.

I thought I had it working but, I am having trouble where it says it cannot find the pipe name.

I hope its something simple i missed. Thanks!

Code: [Select]
(defun C:z2pn (/ c3d c3ddoc location ntwrk ntwrks prod prodstr pt pipe pipename pipes)
  (vl-load-com)
  (if (setq C3D    (strcat "HKEY_LOCAL_MACHINE\\"
                           (if vlax-user-product-key
                             (vlax-user-product-key)
                             (vlax-product-key)
                           )
                   )
            C3D    (vl-registry-read C3D "Release")
            C3D    (substr
                     C3D
                     1
                     (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1))
                   )
            C3D    (vla-getinterfaceobject
                     (vlax-get-acad-object)
                     (strcat "AeccXUiPipe.AeccPipeApplication." C3D)
                   )
            C3Ddoc (vla-get-activedocument C3D)
      )
    (progn
      (setq ntwrks (vlax-get c3ddoc 'pipenetworks))
      (setq pipename (getstring "\nPipe name to zoom to: " t))
      (vlax-for ntwrk ntwrks
        (if (not strc)
          (progn
            (vl-catch-all-apply
              '(lambda ()
                 (setq pipes (vlax-get ntwrk 'pipes))
                 (setq pipe (vlax-invoke pipes 'item pipename))
               )
              '()
            )
          )
        )
      )
      (if strc
        (progn
          (setq location (vlax-get pipe 'position))
          (setq pt (list (vlax-get location 'x) (vlax-get location 'y)))
          (command "zoom" "c" pt "40")
        )
        (progn
          (princ (strcat "\nPipe \"" pipename "\" not found."))
        )
      )
    )
  )
  (princ)
)
 
Civil3D 2020

jvillarreal

  • Bull Frog
  • Posts: 327
Re: Zoom to a Pipe - Help
« Reply #1 on: June 15, 2021, 03:47:30 PM »
It looks like you need to replace "strc" with "pipe", and I don't think pipes have the position property.

Maybe you'd prefer having the option to zoom to either, like below?
Code: [Select]
;Provides ability to zoom to object by typing network part name or picking object in profile


(defun c:Zoom2Object (/   C3D     C3DDOC    LOCATION NTWRK
NTWRKS   PROD     PRODSTR   PT   PT1 OBJ
objname  STRUCTURES OBJ2ZM
       )
  (vl-load-com)
  (if (setq C3D    (strcat "HKEY_LOCAL_MACHINE\\"
   (if vlax-user-product-key
     (vlax-user-product-key)
     (vlax-product-key)
   )
   )
    C3D    (vl-registry-read C3D "Release")
    C3D    (substr
     C3D
     1
     (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1))
   )
    C3D    (vla-getinterfaceobject
     (vlax-get-acad-object)
     (strcat "AeccXUiPipe.AeccPipeApplication." C3D)
   )
    C3Ddoc (vla-get-activedocument C3D)
      )
    (progn
      (setq ntwrks (vlax-get c3ddoc 'pipenetworks))     
      (setq obj2zm (LM:select-or-text "\nSelect Profile Object or Enter Part Name: " '((0 . "AECC_GRAPH_PROFILE_NETWORK_PART"))))
      (setq objname (if (= (TYPE obj2zm) 'STR) obj2zm (vla-get-name (vlax-ename->vla-object obj2zm))))
      (vlax-for ntwrk ntwrks
(if (not obj)
  (progn
    (vl-catch-all-apply
      '(lambda ()
(setq structures (vlax-get ntwrk 'structures))
(setq obj (vlax-invoke structures 'item objname))
       )
      '()
    )
    (if (not obj)
    (vl-catch-all-apply
      '(lambda ()
(setq pipes (vlax-get ntwrk 'pipes))
(setq obj (vlax-invoke pipes 'item objname))
       )
      '()
    )
    );if
  )
)
      )

      (cond
((not obj)
  (princ (strcat "\nObject \"" objname "\" not found."))
)
((= (vla-get-objectname obj) "AeccDbStructure")
  (setq location (vlax-get obj 'position))
  (setq pt (list (vlax-get location 'x) (vlax-get location 'y)))
  (command "zoom" "c" pt "20")
)
((= (vla-get-objectname obj) "AeccDbPipe")
  (setq pt (vlax-safearray->list (vlax-variant-value (vlax-get-property obj 'PointAtParam 0))))
  (setq pt1 (vlax-safearray->list (vlax-variant-value (vlax-get-property obj 'PointAtParam 1))))
  (command "zoom" "w" pt pt1)
  (vla-highlight obj T)
)
(T
  (princ (strcat "\nObject \"" objname "\" not found."))
)
      )
    )
  )
  (princ)
)
 

;; Selection or Text  -  Lee Mac
;; Prompts the user to select an object or enter an arbitrary string.
;; msg - [str] [Optional] Prompt string
;; ftr - [lst] [Optional] ssget filter list
;; Returns: [ent/str] Entity name of selected entity or entered string; "" if enter is pressed.

(defun LM:select-or-text ( msg ftr / gr1 gr2 rtn sel )
    (setq msg (princ (cond (msg) ("\nSelect object: ")))
          rtn ""
    )
    (while
        (progn
            (setq gr1 (grread nil 14 2)
                  gr2 (cadr gr1)
                  gr1 (car  gr1)
            )
            (cond
                (   (= 3 gr1)
                    (if (ssget gr2) ;; nentselp is slow for xrefs
                        (if (setq sel (ssget gr2 ftr))
                            (progn (setq rtn (ssname sel 0)) nil)
                            (princ (strcat "\nInvalid object selected." msg))
                        )
                        (princ (strcat "\nMissed, try again." msg))
                    )
                )
                (   (= 2 gr1)
                    (cond
                        (   (< 31 gr2 127)
                            (setq rtn (strcat rtn (princ (chr gr2))))
                        )
                        (   (= 13 gr2)
                            nil
                        )
                        (   (and (= 8 gr2) (< 0 (strlen rtn)))
                            (setq rtn (substr rtn 1 (1- (strlen rtn))))
                            (princ "\010 \010")
                        )
                        (   t   )
                    )
                )
                (   (= 25 gr1)
                    nil
                )
                (   t   )
            )
        )
    )
    rtn
)
(defun c:Z2O (/)(c:zoom2object))


MSTG007

  • Gator
  • Posts: 2508
  • I can't remeber what I already asked! I need help!
Re: Zoom to a Pipe - Help
« Reply #2 on: June 16, 2021, 01:40:07 PM »
That is what I was trying to do. When I was swapping the strc out for pipes, i did not think to look at that property.

Code: [Select]
((= (vla-get-objectname obj) "AeccDbPipe")
  (setq pt (vlax-safearray->list (vlax-variant-value (vlax-get-property obj 'PointAtParam 0))))
  (setq pt1 (vlax-safearray->list (vlax-variant-value (vlax-get-property obj 'PointAtParam 1))))

Thank you for sharing. Great job.
Civil3D 2020