Hi again, thought I would provide some more information.
I've attached an image of one of the regions that I'm trying to run Massprop on. There are 183 similar regions above this one that are each 1 unit above the next. After running Massprop on one of the sections, it moves the UCS up 1 unit and then runs massprop on the next sections. My full code is here:
(defun c:MP-2D (/ FileName counter)
(setq counter 1)
;Ensure that the program starts at the bottom
(command "ucs" "Named" "Restore" "2d")
;ENTER NUMBER OF SECTION CUTS. Enter as counter max value below:
(while (<= counter 3)
;Assign name of .mpr files to be created
(setq FileName (strcat "SectionNumber" (itoa counter)))
;Select the region
(setq Region (ssget "W" '(-50 50) '(50 -50) '((0 . "REGION"))))
;(setq Region (entsel))
;Pull the centroid coordinates out of the region's properties
(setq centroid (vlax-safearray->list (vlax-variant-value (vlax-get-property (vlax-ename->vla-object (car Region)) "Centroid"))))
;Pull the Principal Directions out of the region's properties
;Note that the resulting list is in the form (x1 x2 y1 y2)
;Therefore, the user should chose the first and third inputs, or the second and fourth
(setq PrDir (vlax-safearray->list (vlax-variant-value (vlax-get-property (vlax-ename->vla-object (car Region)) "PrincipalDirections"))))
;Selects the first and third values from the extracted Principal Directions
(setq PrDirx (list (nth 0 PrDir) (nth 2 PrDir)))
;Set the USC such that the origin is at the centroid of the region,
;and the X-axis is along one of the Principal Directions
(command "ucs" "_NON" centroid "_NON" PrDirx "")
;Run MASSPROP on the region and save the output to a file
(command "_MASSPROP" Region "" "_Y" FileName)
;Add one to the counter
(setq counter (+ counter 1))
;Return to original USC before moving the UCS to the next section height
(command "ucs" "previous")
;MOVE THE UCS UP TO THE HEIGHT OF THE NEXT SECTION CUT
;Change z-coordinate in all three points below to be
;equal to the height between sections
;i.e., '(0 0 deltaz) '(1 0 deltaz) '(0 1 deltaz)
(command "ucs" "_3p" "_NON" '(0 0 1) "_NON" '(1 0 1) "_NON" '(0 1 1))
))
As I said in my previous post, if I use "entsel" to select the region, then the code runs perfectly. If I try to use "ssget", it doesn't like it. Because there are 184 regions to run massprop on, though, I need this code to be fully automated (i.e. I don't want to have to select each region individually as the code runs).
Now, I've done some more thinking since my original post, and I have realized that the type of variable that "Region" is differs between using ssget and entsel. If I put a breakpoint at the "(setq centroid....)" line of code, run it using ssget for Region, and then use the "type" function in the Visual Lisp Console, it returns
_1_$ type Region
#<SUBR @000000004bcfea20 TYPE>
<Selection set: 73>
However, if I do the same using entsel instead of ssget, the "type" function returns
_1_$ type Region
#<SUBR @000000004bcfea20 TYPE>
(<Entity name: 55e26e80> (5.14935 1.4122 0.0))
So, it seems that using entsel results in Region being an entity, while ssget results in Region being a selection set? Am I understanding that correctly?
It seems that then the code stops running and displays an error when it tries to run the next line and gets to (vlax-ename->vla-object (car Region)) when Region is a selection set instead of an entity.
How can I use ssget to select my region and store it as an entity?
Thanks in advance for any and all help!