Jump to content

Good morning all, i am trying to modify code bellow to get total pipe length in a 3D model Plant 3D, code look for all piping that is set to status as new but I am getting an error message saying: "no function definition: Status", any idea? thanks!


f.fhelix

Recommended Posts

(defun c:TL ( / selnew selAll status Length)
  (vl-load-com)
  (setq selnew(ssadd))
  (setq Length 0)
  
   (if (setq selAll (ssget "x" '((0 . "ACPP*"))))
        (progn
            (setq i 0
                  n (sslength selAll)
            )
            (while (< i n)
				(setq ent (ssname selAll i)) 
				;convert to vl object
				(setq vlaObj (vlax-ename->vla-object ent))
				(if (vlax-property-available-p vlaObj 'CutLength)
				(progn
					(setq status (vlax-get-property vlaObj 'CutLength))
					(ssadd ent selnew)
				)
				)
				(setq Length (status + Length))
				(setq i (1+ i))
            );while
        )
    )
	
  (sssetfirst nil selnew)
  alert (Length)
  (princ)
)

 

Link to comment
Share on other sites

Your alert is missing a ( infront. also (length) makes it look for a function of that name and causes the error "no function definition:"

If you tried to do (alert length) it would still error since that variable is a number you need to use rtos to convert it to a string.

 

(defun c:TL ( / selnew selAll len)
  (vl-load-com)
  (setq selnew (ssadd))
  (setq len 0)
  (if (setq selAll (ssget "_X" '((0 . "ACPP*"))))
    (foreach ent (mapcar 'cadr (ssnamex selAll))
      (setq vlaObj (vlax-ename->vla-object ent))
      (if (vlax-property-available-p vlaObj 'CutLength)
        (progn
          (setq len (+ (vlax-get-property vlaObj 'CutLength) len))
          (ssadd ent selnew)
        )
      )

    )
  )
  (sssetfirst nil selnew)
  (if (> len 0)
    (alert (strcat "Total Length: " (rtos len 2 3)))
  )
  (princ)
)

 

Edited by mhupp
update code
Link to comment
Share on other sites

Thanks for reply, now not showing that error anymore, get a different error, "; error: bad argument type: numberp: nil"

 

and what is this doing? (foreach vp (mapcar 'cadr (ssnamex selAll)) can you explain it to me?

 

Thanks.

Link to comment
Share on other sites

VP should be ent. (updated code) it basically makes a list of all entity's names from selection set selAll and feeds them one at a time to below code as the variable ent. its so you don't have to use a counter to step thought the selection set.

 

(foreach ent (mapcar 'cadr (ssnamex selAll)) ;can be used for ssget "_X"
(foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) ;is used for all other ssgets

 

Link to comment
Share on other sites

Thanks for the explanation, i have changed the code, now error comes followed by a number like this "; error: bad argument type: numberp: "44.714367"" witch i checked and its not the pipe length, trying to fig what that number means... I've placed 3'-8 11/16" pipe in the model and ran the code, so code returns that error followed by that number above. 

 

Thank you! 

Link to comment
Share on other sites

44.714367 is the total length in inches and is close to 3'-8 11/16"

If you want feet and inches rtos needs to use option 4 and 4 precision to display the closet 16th.

 

Its calculating the correct distance. 'CutLength might be coming in as a string. so use either of the lines after progn.

 

(defun c:TL ( / selnew selAll len)
  (vl-load-com)
  (setq selnew (ssadd))
  (setq len 0)
  (if (setq selAll (ssget "_X" '((0 . "ACPP*")))) ;I don't know what this is add on?
    (foreach ent (mapcar 'cadr (ssnamex selAll))
      (setq vlaObj (vlax-ename->vla-object ent))
      (if (vlax-property-available-p vlaObj 'CutLength) 
        (progn
          (setq len (+ (vlax-get vlaObj 'CutLength) len)) ;'CutLength needs to be a number to use this line
          ;(setq len (+ (distof (vlax-get vlaObj 'CutLength)) len)) ;if 'CutLength is a string use this line.
          (ssadd ent selnew)
        )
      )
    )
  )
  (sssetfirst nil selnew)
  (if (> len 0)
    (alert (strcat "Total Length: " (rtos len 4 4)))
  )
  (princ)
)

 

Link to comment
Share on other sites

(if (setq selAll (ssget "_X" '((0 . "ACPP*")))) This line is to select all and filter all piping class in plant 3D so avoid the lisp to pick elbows flanges and etc...

 

cade above if i draw a single pipe and set for 20' it returns 240 witch is ok, but if i add 20' more parallel it still reads 240 instead  480. 

 

look the original code how it looks likes: i tried to modify the original code to select all in my 3D model sort all piping class, pick all piping that status was "new" and return a total length.

 

the original codes works perfect it gets me the total length perfect, but it do not excludes piping that status is "existing"  

 

so if i place 20' of new pipe and 20' of existing piping the original code will returns 40'. but  i was expecting 20'.   Thanks Again!

 

 

 

(defun c:TTL ( / mySet total selAll cutLength)
  (vl-load-com)
  (setq mySet(ssadd))
  (setq total 0)
  
   (if (setq selAll (ssget "x" '((0 . "ACPP*"))))
        (progn
            (setq i 0
                  n (sslength selAll)
            )
            (while (< i n)
                (setq ent (ssname selAll i)) 
                ;convert to vl object
                (setq vlaObj (vlax-ename->vla-object ent))
                (if (vlax-property-available-p vlaObj 'CutLength)
                    (progn
                        (setq cutLength (vlax-get-property vlaObj 'CutLength))
                        (setq total (+ total (atof cutLength)))
                    )
                )
                (setq i (1+ i))
            );while
        )
    )
    (alert (rtos total))
  (princ)
)

Link to comment
Share on other sites

Use this on existing and new pipe their might be a property like status or something you can filter.

 

--edit

because i never seen CutLenght before

 

;;----------------------------------------------------------------------------;;
;; Dump all methods and properties for selected objects               
(defun C:VDumpIt (/ ent)
  (if (setq SS (ssget))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (vlax-Dump-Object (vlax-Ename->Vla-Object ent) t)
      (textscr)
    )
  )
  (princ)
)

 

Edited by mhupp
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...