Author Topic: AutoStacking  (Read 4003 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1206
Re: AutoStacking
« Reply #15 on: October 29, 2010, 01:32:20 PM »
Lee, I think your name appears in our customization more than mine.   :-D

Thank you, I think i understand some of your code, but I don't understand the following bits of your code:
Code: [Select]
(setq RegEx (vlax-create-object "VBScript.RegExp"))
(LM:RegExReplace RegEx "{\\H0.7x;\\S$1#$2;}" "-?(\\d+)/(\\d+)" (LM:GetTextString e))


(defun LM:RegExReplace ( reg new pat str )
  ;; Lee Mac 2010
  (mapcar '(lambda ( prop value ) (vlax-put-property reg prop value)) '(pattern global ignorecase) (list pat actrue acfalse))
  (vlax-invoke reg 'replace str new)
)

Lee Mac

  • Seagull
  • Posts: 12268
  • London, England
Re: AutoStacking
« Reply #16 on: October 29, 2010, 01:35:58 PM »
That's the part that uses Regular Expressions to make the replacements, Joe Burke introduced me to those whilst working on the Batch Find & Replace program.

I use this reference:

http://msdn.microsoft.com/en-us/library/yab2dx62%28VS.85%29.aspx

cmwade77

  • Swamp Rat
  • Posts: 1206
Re: AutoStacking
« Reply #17 on: October 29, 2010, 01:39:52 PM »
Wow, I am going to have to look into that further, when I have more time. Right now, I am trying to catch up with the standards changes that my boss approved (finally) and trying to get "real work" out....LOL

cmwade77

  • Swamp Rat
  • Posts: 1206
Re: AutoStacking
« Reply #18 on: October 29, 2010, 02:50:08 PM »
With regards to first one, I believe the settings are stored here:

Code: [Select]
(strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\MTEXT")
Don't quote me on that though...

As for the second, I should imagine you could use a RegExp expression to replaces strings matching something like (\S)/(\S), then replace it with {$1#$2} or similar..



Yes, that is indeed where it is stored, here is what I have:
* EDIT: I got it working now:
Code: [Select]
(if (/= (vl-registry-read (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\MTEXT") "AutoStack") 1)
(vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\MTEXT") "AutoStack" 1)
)
(if (/= (vl-registry-read (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\MTEXT") "ConvertStackToArch") 1)
(vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\MTEXT") "ConvertStackToArch" 1)
)
(if (/= (vl-registry-read (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\MTEXT") "TrimLeadingStackBlank") 1)
(vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\MTEXT") "TrimLeadingStackBlank" 1)
)
« Last Edit: October 29, 2010, 04:11:19 PM by cmwade77 »

Lee Mac

  • Seagull
  • Posts: 12268
  • London, England
Re: AutoStacking
« Reply #19 on: October 29, 2010, 06:49:28 PM »
lol why not set a variable:

Code: [Select]
(setq root (vl-registry-read (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\MTEXT"))
Save you some typing  :-D

I suppose you could also use an expression like this, but it makes it less readable:

Code: [Select]
(mapcar
  (function
    (lambda ( key value )
      (if (/= value (vl-registry-read root key))
        (vl-registry-write root key value)
      )
    )
  )
  '("AutoStack" "ConvertStackToArch" "TrimLeadingStackBlank")
  '(1 1 1)
)

Crank

  • Swamp Rat
  • Posts: 1441
Re: AutoStacking
« Reply #20 on: October 30, 2010, 03:52:42 PM »
Didn't try this, but is it necessary to read the key first? Can't you just write to the register:
Code: [Select]
(vl-registry-write root "AutoStack" 1)
(vl-registry-write root "ConvertStackToArch" 1)
(vl-registry-write root "TrimLeadingStackBlank" 1)

 Vault Professional 2018     /      Building Design Suite Ultimate 2017     /     AEC Collection 2018 + 2019 +2020

cmwade77

  • Swamp Rat
  • Posts: 1206
Re: AutoStacking
« Reply #21 on: November 02, 2010, 11:29:04 AM »
Didn't try this, but is it necessary to read the key first? Can't you just write to the register:
Code: [Select]
(vl-registry-write root "AutoStack" 1)
(vl-registry-write root "ConvertStackToArch" 1)
(vl-registry-write root "TrimLeadingStackBlank" 1)

I don't like writing to the registry if the values are already correctly set.....too many writes to the registry causes problems with windows.

Crank

  • Swamp Rat
  • Posts: 1441
Re: AutoStacking
« Reply #22 on: November 02, 2010, 12:00:10 PM »
[...] too many writes to the registry causes problems with windows.
Windows also checks the key/value first. If the value is already 1 then nothing happens. :)

 Vault Professional 2018     /      Building Design Suite Ultimate 2017     /     AEC Collection 2018 + 2019 +2020

cmwade77

  • Swamp Rat
  • Posts: 1206
Re: AutoStacking
« Reply #23 on: November 02, 2010, 12:30:25 PM »
Ok, I didn't know that, I just wanted to avoid the possibility of extra writes.

cmwade77

  • Swamp Rat
  • Posts: 1206
Re: AutoStacking
« Reply #24 on: November 03, 2010, 01:41:50 PM »
This needs a lot more error trapping, but this is where I was going with the Regular Expression usage:

Code: [Select]
(defun c:test ( / RegEx i ss e )
  (vl-load-com)
  ;; Lee Mac 2010

  (setq RegEx (vlax-create-object "VBScript.RegExp"))

  (if (setq i -1 ss (ssget "_:L" '((0 . "MTEXT"))))
    
    (while (setq e (ssname ss (setq i (1+ i))))
      (vla-put-TextString (vlax-ename->vla-object e)
        (LM:RegExReplace RegEx "{\\H0.7x;\\S$1#$2;}" "-?(\\d+)/(\\d+)" (LM:GetTextString e))
      )
    )
  )

  (vlax-release-object RegEx)
  (princ)
)

(defun LM:RegExReplace ( reg new pat str )
  ;; Lee Mac 2010
  (mapcar '(lambda ( prop value ) (vlax-put-property reg prop value)) '(pattern global ignorecase) (list pat actrue acfalse))
  (vlax-invoke reg 'replace str new)
)

(defun LM:GetTextString ( ent )
  ;; Lee Mac 2010
  
  (  (lambda ( string )
       (mapcar
         (function
           (lambda ( pair )
             (if (vl-position (car pair) '(1 3))
               (setq string (strcat string (cdr pair)))
             )
           )
         )
         (entget ent)
       )
       string
     )
    ""
  )
)

Lee,

This code works well, but I can't seem to get it to work with MLEADERs. Please note that I have tried removing the filter and just selected the mleaders to experiment with. Any ideas on how to accomplish this? The formatting is the same as for MTEXT.


EDIT: I think I got it, please see attached code and let me know if there is a better way to handle this.
« Last Edit: November 03, 2010, 02:33:50 PM by cmwade77 »

cmwade77

  • Swamp Rat
  • Posts: 1206
Re: AutoStacking
« Reply #25 on: November 09, 2010, 12:05:32 PM »
Ok, one more question on this, does anyone have any ideas on how to modify this to work with tables?

I am going to keep hacking at it, but haven't been able to get anywhere yet.