Jump to content

Recommended Posts

Posted (edited)

I am trying to retrieve the current dimension style on an open cad file to execute some of my other lisps instead of (Alert blah...), but am not successful.

Could someone take a quick look at this and let me know where I am getting it wrong? i had a quick look at tblnext and tblsearch and I think it is right! but maybe VLA could do this more efficiently - I have not gotten too deep into LISP though.

 

I also have two standards ( "STANDARD" and "Standard") depending on which one is the current dim style my code changes. is there a way to make it Case sensitive?

; condition based on current dim stlye
; "Tx Arial 1.65" "Tx CityBlueprint 2.38" "Standard"
(defun c:test (/ D1)

  (setq D1 (tblnext "DIMSTYLE")) ; getting current dimstyle name
  (setq D1 (cdr (assoc 2 D1))) ; getting dimstyle name
  
(while  (/= D1 nil) ; if dimstyle is not nil then proceed
  (setq D1(tblsearch "DIMSTYLE" D1)) ;; searching for dimstyle
    
 (cond
   ( (= (cdr (assoc 2 D1)) "Standard")
    (alert "Standard is selected")
   )
    
   ( (= (cdr (assoc 2 D1)) "Tx Arial 1.65")
    (alert "Tx Arial 1.65 is selected")
   )
    
   ( (= (cdr (assoc 2 D1)) "Tx CityBlueprint 2.38")
    (alert "Tx CityBlueprint 2.38 is selected")
   )
   
 ); end cond
    
); end while
(princ)
)

Please help

SAMPLE DIMENSION.dwg

Edited by Sambuddy
edit text
Posted

@devitg I am not sure it this helps but I just uploaded the dims.

my lisp is complete just imagine instead of Alert I have c:do-1

 

thanks

Posted (edited)

I think you overprogrammed...

Shouldn't this be also good ?

 

(defun c:test nil
  (cond
    ( (= (getvar 'dimstyle) "Standard")
      (alert "Standard is selected")
    )
    ( (= (getvar 'dimstyle) "Tx Arial 1.65")
      (alert "Tx Arial 1.65 is selected")
    )
    ( (= (getvar 'dimstyle) "Tx CityBlueprint 2.38")
      (alert "Tx CityBlueprint 2.38 is selected")
    )
    ( t
      (alert "Current DIMSTYLE not match any of hardcoded choices...")
    )
  )
  (princ)
)

 

Edited by marko_ribar
Posted
Quote

I think you overprogrammed...

Shouldn't this be also good ?

I am ashamed of myself - thank you for the getvar 'dimstyle.

I knew there is a variable but I kept looking into -dimstyle and never thought about your approach.

 

Thank you very much marko_rebar

I guess I am not the one grinding on boxing day! hah! 

 

Happy Holidays 

Posted

now that I have you here, could you help me with another problem I have been facing:

(if (not c:BLAH)(load "BLAH"))

is there another way to test whether a lisp is or not?

Posted (edited)

 

 

3 hours ago, Sambuddy said:

..... is there a way to make it Case sensitive

 

assume you have list

 

(setq lst '( "STANDARD"  "standard" "Tx Arial 1.65" "Tx CityBlueprint 2.38" ) )

 

case sensitive use wcmatch 

(alert
  (strcat (cond ( (car (vl-remove-if-not ''((x) (wcmatch x (getvar 'dimstyle))) lst) ) )
        	("oops! Nothing"))
      	" is selected"
      )
  )

 

FWIW another but not case sensitive

(alert
  (if (setq x (vl-position (getvar 'dimstyle) lst))
    (strcat (nth x lst) " is selected")
    "Current DIMSTYLE not match any of hardcoded choices..."
    )
  )

 


 

Edited by hanhphuc
syntax color
  • 2 weeks later...
Posted

@hanhphuc

Great! Thank you very much.

I can now arrange my lisp based on the dim style criteria much more easier that changing my text every time.

 

Thanks a lot!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...