vla-copyobjects help

vla-copyobjects help

msarqui
Collaborator Collaborator
1,767 Views
10 Replies
Message 1 of 11

vla-copyobjects help

msarqui
Collaborator
Collaborator
Hi guys.
Using vla-copyobjects , what would be the best (fast) way to copy all dimensions in a drawing and then change the dimstyle of those new copies. Let's say, from dimstyle "A" to "B".
Don't need to move the new copies, they can stay at the same insertion point as the original ones. Yes, they will be overlapping.
May I have some exemples?
Thanks for helping.
0 Likes
Accepted solutions (1)
1,768 Views
10 Replies
Replies (10)
Message 2 of 11

DannyNL
Advisor
Advisor
Accepted solution

See code below.

This will copy all dimensions in the drawing on the same location and change the dimension style of the new dimensions to TEST.

 

(defun c:Test (/ ss ent obj)
   (if
      (setq ss (ssget "_X" '((0 . "DIMENSION"))))
      (progn
         (foreach ent (mapcar 'cadr (ssnamex ss))
            (setq obj (vla-copy (vlax-ename->vla-object ent)))
            (vla-put-StyleName obj "TEST")
         )
      )
   )
   (princ)
)
0 Likes
Message 3 of 11

Kent1Cooper
Consultant
Consultant

@DannyNL wrote:

....

This will copy all dimensions in the drawing on the same location and change the dimension style of the new dimensions to TEST.


[Actually, in case it might matter for some reason, it changes the Style of the original  Dimension objects, not the new  ones.]

Kent Cooper, AIA
0 Likes
Message 4 of 11

DannyNL
Advisor
Advisor

@Kent1Cooper wrote:

[Actually, in case it might matter for some reason, it changes the Style of the original  Dimension objects, not the new  ones.]


No, it does not. The new copies will have the changed style and the original dimensions will be untouched.

VLA-COPY returns the id of the newly created object and that's the object the style will be changed in.

0 Likes
Message 5 of 11

msarqui
Collaborator
Collaborator

Faster then the code was your anwer 🙂

Thanks for helping!

 

0 Likes
Message 6 of 11

DannyNL
Advisor
Advisor

Glad it works and I could help Smiley Happy

0 Likes
Message 7 of 11

Kent1Cooper
Consultant
Consultant

@DannyNL wrote:

@Kent1Cooper wrote:

[... it changes the Style of the original  Dimension objects....]


No, it does not. ....


I misread something about it.

 

Since the OP asked for examples, as an alternative I was looking at using DIMOVERRIDE so that the copies could be made, and the Style could be changed, of all of them at once, rather than needing to step through the selection and do it to each Dimension separately.  But for some unknown reason, DIMOVERRIDE will not accept DIMSTYLE as a Dimensioning Variable to override, though Help includes no indication of such a limitation, that I can find.  [Anyway, if it worked to do it that way, it would have the limitation that it could only do the ones in the current space, so if you have Dimensions in both Model and Paper space, or in multiple Paper space Layouts, and you want to get all of them, it wouldn't do it without changing spaces and running it in each.]

Kent Cooper, AIA
0 Likes
Message 8 of 11

DannyNL
Advisor
Advisor

Mmhhh...didn't look at it that way to be honest.

I figured since I already have the new object after the copy action, to just to put the new dimension style into the properties. Easiest and shortest way to code for me Smiley Wink

0 Likes
Message 9 of 11

Kent1Cooper
Consultant
Consultant

@DannyNL wrote:

.... Easiest and shortest way to code for me


Not shortest, if my idea had been acceptable to the DIMOVERRIDE command, and if it doesn't matter that the originals have their Style changed, rather than the copies:

(defun c:Test (/ ss)
  (if
    (setq ss (ssget "_X" '((0 . "DIMENSION"))))
    (command

      "_.copy" ss "" "_none" "0,0" ""

      "_.dimoverride" "dimstyle" "YourDimensionStyle" "" ss ""

    )
  )
  (princ)
)

 

But since it doesn't accept that particular Dimension System Variable, it won't fly.

Kent Cooper, AIA
0 Likes
Message 10 of 11

DannyNL
Advisor
Advisor

But I didn't say shortest  but shortest for me Smiley Wink

 

I know code can sometimes be (a lot) shorter if I see some of your or others code, but to me readability is more important than a shorter code. And to achieve that for me it is sometimes better to write some additional lines of code to make it more clear and easy to understand what happens a long the way. Not directly at the time when I write the code but more for when I reuse or read it back in a year or so.

 

And there's more than one way to skin a cat, so different solutions will have more or less coding like your example.

0 Likes
Message 11 of 11

msarqui
Collaborator
Collaborator

Hi Kent,

 

I must say, I am your fan because you always try to go further and I have learned alot with your posts.

The only thing for this particulary request of mine is that the code must be done with vla-copyobjects because I am using it inside a reactor.

 

Thanks

0 Likes