Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Subtracting set value from scale factor of multiple blocks

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
taylorscott37
1213 Views, 5 Replies

Subtracting set value from scale factor of multiple blocks

Hi,

 

I work in the solar industry, mainly with rooftop designs.  I'm working with shade profile blocks that are created for a 1m object and scaled based on the objects height (0.5m roof vent? 0.5 scale factor) to show the shade arc that the vent will throw over a year. 

 

My question may be super simple but I have yet to find a solution with many searches on the forums.  I am looking for a routine to take all existing shade blocks in the drawing and subtract a specific value from their current scale factor (x & y).  In other words, take all blocks of a name and subtract 0.15(or any input value) from the existing scale factor.   

 

For the curious, the reason why this is important is we recieve the surveys and shade blocks prior to design of the racking system that the solar modules will be installed on.  The racking we use has a height and the shade thrown by and object is only important in the relation of the height of the object to the solar panel.  So I'm really just looking to take into account the height of the racking, after the fact, in the scale factors of the existing shade blocks.  This height changes project to project. 

 

I've dug around, but haven't found anything close enough for me to be able to modify the code with my basic vba and even less so LISP skills.  Any help is greatly appreciated!   

 

I've attached a sample drawing to help illustrate my problem.

 

Thank you!

 

 

5 REPLIES 5
Message 2 of 6

The blocks in the attached drawing are set to scale uniformly. Are you sure you want to scale them non-uniformly? If so try below code

 

(defun c:somefunc  (/ adoc etdata found subx suby)
 (setq subx (getreal "\nSpecify X Scale reduction: ")
       suby (getreal "\nSpecify Y Scale reduction: "))
 (mapcar '(lambda (x)
           (and (not found)
                (= (vla-get-effectivename (vlax-ename->vla-object x)) "Shadow 10-2")
                (setq found t)
                (vla-put-blockscaling (vla-item (vla-get-blocks (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
                                                "Shadow 10-2")
                                      :vlax-false))
           (entmod (subst (cons 42 (- (cdr (assoc 42 (setq etdata (entget x)))) suby))
                          (assoc 42 etdata)
                          (subst (cons 41 (- (cdr (assoc 41 etdata)) subx)) (assoc 41 etdata) etdata))))
         (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "insert")))))))
 (princ))

non_uniform_blk_scaling.gif

 

Message 3 of 6
Kent1Cooper
in reply to: taylorscott37

@Ranjit_Singh2 beat me to the punch, but since I had worked this up....  This asks for a Block name -- the name in the drawing suggests there would be other Shadow Blocks you might choose -- but I wasn't sure whether that's what you wanted; you can use Ranjit's built-in one if appropriate:

 

(defun C:SDXY ; = Scale Down X and Y
  (/ blkname reduc n blkobj)
  (setq
    blkname (getstring T "\nBlock name: ")
    reduc (getreal "\nReduction in scale factors: ")
  ); setq
  (if (setq ss (ssget "_X" '((0 . "INSERT"))))
    (progn ; then
      (repeat (setq n (sslength ss))
        (setq blkobj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
        (if (= (vla-get-EffectiveName blkobj) blkname)
          (vla-put-Xeffectivescalefactor blkobj (- (vla-get-Xeffectivescalefactor blkobj) reduc))
        ); if
      ); repeat
    ); progn
  ); if
  (princ)
); defun

I took your description to mean you wanted the same  amount of reduction in both  the X and Y scale factors [though I wondered about the Z scale factor].  But I find that since they're defined to scale uniformly, it doesn't matter -- assigning just one  effective scale factor value drags all the others with it.

 

BUT there are some caveats.  In your drawing, some of them are at a scale factor of 0.15, and if you try to take that same amount [as in your description] off, the result will be 0, which won't be accepted [nor a negative value].  What should it do to Blocks for which that would be the result?  Remove  them, since presumably the object in question wouldn't cast a shadow if it's at or below the rack level?

Kent Cooper, AIA
Message 4 of 6

Thanks Ranjit & Kent!

 

That is perfect! I will only be needing to scale uniformly as @Kent1Cooper surmised, but I should have little trouble modifying the code to apply the value to both x and y factors.  Thanks again! 

 

I hope this helps some solar drafter out there in the future. 

 

Best Regards,

Taylor

Message 5 of 6
Kent1Cooper
in reply to: taylorscott37


@taylorscott37 wrote:

.... I should have little trouble modifying the code to apply the value to both x and y factors. ....


You don't need to in mine -- as mentioned, the Y and Z follow along automatically with the application of the X scale factor.

 

And I realized that I had an extraneous (progn) "wrapper" in mine that isn't necessary.  This will do:

(defun C:SDXY ; = Scale Down X and Y
  (/ blkname reduc n blkobj)
  (setq
    blkname (getstring T "\nBlock name: ")
    reduc (getreal "\nReduction in scale factors: ")
  ); setq
  (if (setq ss (ssget "_X" '((0 . "INSERT"))))
    (repeat (setq n (sslength ss))
      (setq blkobj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
      (if (= (vla-get-EffectiveName blkobj) blkname)
        (vla-put-Xeffectivescalefactor blkobj (- (vla-get-Xeffectivescalefactor blkobj) reduc))
      ); if
    ); repeat
  ); if
  (princ)
); defun
Kent Cooper, AIA
Message 6 of 6
taylorscott37
in reply to: Kent1Cooper

Thanks Kent!

 

Again, much appreciated1

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report