Change block unit

Viking_Mike
edited September 2017 in 2D Drafting

I would like to change the block unit of an existing block. I don't see any way to do it with REFEDIT active. I see that it may be possible to redefine with -Block but this isn't really what I would call redefining, more like defining but with fewer options, and then overwriting. Is there a better way?

Comments

  • Save it as a file open the file, Make your changes and read it back in.

  • (defun KGA_Sys_Apply (expr varLst / ret)
      (if (not (vl-catch-all-error-p (setq ret (vl-catch-all-apply expr varLst))))
        ret
      )
    )
    
    ; Units enumerator:
    ;   acInsertUnitsAngstroms 
    ;   acInsertUnitsAstronomicalUnits 
    ;   acInsertUnitsCentimeters 
    ;   acInsertUnitsDecameters 
    ;   acInsertUnitsDecimeters 
    ;   acInsertUnitsFeet 
    ;   acInsertUnitsGigameters 
    ;   acInsertUnitsHectometers 
    ;   acInsertUnitsInches 
    ;   acInsertUnitsKilometers 
    ;   acInsertUnitsLightYears 
    ;   acInsertUnitsMeters 
    ;   acInsertUnitsMicroinches 
    ;   acInsertUnitsMicrons 
    ;   acInsertUnitsMiles 
    ;   acInsertUnitsMillimeters 
    ;   acInsertUnitsMils 
    ;   acInsertUnitsNanometers 
    ;   acInsertUnitsParsecs 
    ;   acInsertUnitsUnitless 
    ;   acInsertUnitsYards 
    (defun c:ChangeBlockUnits ( / doc blk inp)
      (setq doc (vla-get-activedocument (vlax-get-acad-object)))
      (vla-endundomark doc)
      (vla-startundomark doc)
      (initget 128)
      (setq inp (entsel "\nSelect block reference or enter block name: "))
      (cond
        ((vle-stringp inp)
          (setq blk (KGA_Sys_Apply 'vla-item (list (vla-get-blocks doc) inp)))
        )
        ((vl-consp inp)
          (setq blk (vla-item (vla-get-blocks doc) (vla-get-name (vlax-ename->vla-object (car inp)))))
        )
      )
      (if blk
        (vla-put-units blk acInsertUnitsMillimeters) ; Change acInsertUnitsMillimeters to suit your needs.
        (prompt "\nError: block not found ")
      )
      (vla-endundomark doc)
      (princ)
    )
    
  • Roy's code is great (as usual), but if you feel uncomfortable with adapting it to your needs, you might try (app)loading the attached file, and just follow the prompts. Be warned that is has no error handling, and that you should probably not use the 'all' option (unless you use the same units in model and paper space).

  • Thanks. I only know enough programming to make minor tweaks but the second one looks a little simpler, more what I was expecting.

This discussion has been closed.