Jump to content
DesmetMartin

Help me FIX this LISP about DIMENSIONS

Recommended Posts

DesmetMartin

Hello,

 

Could anyone help me let this LISP work.

The lisp should go to the layer you choose (by pressing 1 or 2) when in a *DIM* command.

 

After placing the dimension the layer should go back to the layer it was before selecting a *DIM* command.

 

This is the code now.

 

; AFKORTINGEN VAN DE VARIABELEN
 ;  ADDL Automatic dimension layer

;****************************************************************************

(defun CommandReactor:Start ()
 (or *CommandReactor*
     (setq *CommandReactor*
            (vlr-command-reactor
              nil
              '(
                (:vlr-commandcancelled . CommandReactor:CommandEnded)
                (:vlr-commandended . CommandReactor:CommandEnded)
                (:vlr-commandfailed . CommandReactor:CommandEnded)
                (:vlr-commandwillstart . CommandReactor:CommandWillStart)
               )
            )
     )
 )
 (prompt "\nCommand reactor loaded. ")
 (princ)
)

;****************************************************************************

(defun CommandReactor:CommandEnded (rea cmd)
 (if (and *OldClayer*
          (wcmatch (strcase (car cmd)) "*DIM*")
     )
   (progn
     (setvar 'clayer *OldClayer*)
     (setq *OldClayer* nil)
 
   )
 )
)

;****************************************************************************
(defun CommandReactor:CommandWillStart (rea cmd)
 (if (wcmatch (strcase (car cmd)) "*DIM*")
   	(progn
     	  (setq *OldClayer* (getvar 'clayer))
     	  (vla-add
	(vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
	  
; Kiezen van de DIM layer 
	(setq ADDL 0)
 		   (while (or (< ADDL 1) (> ADDL 2))
   			(setq ADDL (getint "\nInput the DIM layer: Dim. (1), Dim. front (2): ")))
) ; end while


;ADDL = 1, Dimension layer
(if (= ADDL 1)
	(progn
		(command "_layer" "_m" "S-DIMENSIONS" "_c" "3" "" "")
	); progn
); if (=ADDL 1)

;ADDL = 2, Dimension front layer
(if (= ADDL 2)
	(progn
		(command "_layer" "_m" "S-DIMENSIONS front" "_c" "3" "" "")
	); progn
); if (=ADDL 2)

(setvar 'clayer *OldClayer*)


   )
 )
)

;****************************************************************************
(CommandReactor:Start)
(princ)


;****************************************************************************
;****************************************************************************
;****************************************************************************
;****************************************************************************


 

Please help!

Thanks!

Share this post


Link to post
Share on other sites
Dadgad

Welcome to CADTutor. :)

 

You would likely be interested to check out the following gem by Lee Mac.

 

http://www.lee-mac.com/layerdirector.html

 

One of my all time favorites from Lee's wonderful website.

 

Thanks Lee! :beer:

Share this post


Link to post
Share on other sites
DesmetMartin

Thank you!

 

The LISP I posted is of the same principle of Lee Mac his LISP.

The only 'extra' I am searching for is when you activate, a DIM command you get to choose a number which will give you the layer behind the number.

 

If you load the LISP I've posted, you'll see what I mean.

The only problem is that there is a fault in the LISP or that there's something missing and I don't know what.

 

 

I hope that someone can help me here with this.

Share this post


Link to post
Share on other sites
DesmetMartin

I still need help with this. :(

Share this post


Link to post
Share on other sites
marko_ribar

Here, I've modified it a little :

 

; AFKORTINGEN VAN DE VARIABELEN
;  ADDL Automatic dimension layer

;****************************************************************************

(defun CommandReactor:Start ()
 (or *CommandReactor*
     (setq *CommandReactor*
            (vlr-command-reactor
              nil
              '(
                (:vlr-commandcancelled . CommandReactor:CommandEnded)
                (:vlr-commandended . CommandReactor:CommandEnded)
                (:vlr-commandfailed . CommandReactor:CommandEnded)
                (:vlr-commandwillstart . CommandReactor:CommandWillStart)
               )
            )
     )
 )
 (prompt "\nCommand reactor loaded. ")
 (princ)
)

;****************************************************************************

(defun CommandReactor:CommandEnded ( rea cmd )
 (if (wcmatch (strcase (car cmd)) "*DIM*")
   (progn
     (vla-put-layer (vlax-ename->vla-object (entlast)) (vla-get-name *nlay*))
     (vlax-release-object *nlay*)
     (setq *nlay* nil)
   )
 )
)

;****************************************************************************
(defun CommandReactor:CommandWillStart ( rea cmd / ADDL )
 (if (wcmatch (strcase (car cmd)) "*DIM*")
   (progn
; Kiezen van de DIM layer 
     (setq ADDL 0)
     (while (or (< ADDL 1) (> ADDL 2))
       (setq ADDL (getint "\nInput the DIM layer: Dim. (1), Dim. front (2): "))
     ) ; end while

;ADDL = 1, Dimension layer
     (if (= ADDL 1)
       (progn
         ;;;(command "_layer" "_m" "S-DIMENSIONS" "_c" "3" "" "")
         (setq *nlay* (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "S-DIMENSIONS"))
         (vla-put-color *nlay* 3)
       ); progn
     ); if (=ADDL 1)

;ADDL = 2, Dimension front layer
     (if (= ADDL 2)
       (progn
         ;;;(command "_layer" "_m" "S-DIMENSIONS front" "_c" "3" "" "")
         (setq *nlay* (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "S-DIMENSIONS front"))
         (vla-put-color *nlay* 3)
       ); progn
     ); if (=ADDL 2)
   )
 )
)

;****************************************************************************
(vl-load-com)
(CommandReactor:Start)
(princ)


;****************************************************************************
;****************************************************************************
;****************************************************************************
;****************************************************************************

Hope this is what you needed...

M.R.

Edited by marko_ribar

Share this post


Link to post
Share on other sites
Tharwat

Hi,

 

Although that I think it is not a good way to use reactor for such a task but this is up to you.

 

NOTE:

  • It is better to change the string that represents the name of the command from *DIM* to your desired command name because with current string would trigger the reactor even if you call the command DymStyle.
  • You can not use command calls with reactors.

 

Here is my modification to handle all events I think with a function to end the reactor when you are not in need of the reactor anymore.

 

(vl-load-com)
;;	Author: Tharwat Al Shoufi	;;
;;	Date: 09.May.2016		;;
(defun c:CommandReactorStart nil
 (or *CommandReactor*
     (setq *CommandReactor*
            (vlr-command-reactor
              nil
              '(
                (:vlr-commandcancelled . CommandReactor:CommandBroken)
                (:vlr-commandended . CommandReactor:CommandEnded)
                (:vlr-commandfailed . CommandReactor:CommandBroken)
                (:vlr-commandwillstart . CommandReactor:CommandWillStart)
                )
              )
           )
     )
 (prompt "\nCommand reactor Started.")
 (princ)
 )
;;					;;
;;					;;
(defun c:CommandReactorEnd nil
 (if *CommandReactor*
   (vlr-remove *CommandReactor*)
   )
 (prompt "\nCommand reactor Disabled !")
 (princ)
 )
;;					;;
;;					;;
(defun CommandReactor:CommandEnded (rea cmd)
 (if (and *OldClayer*
          (tblsearch "LAYER" *OldClayer*)
          (wcmatch (strcase (car cmd)) "*DIM*")
          )
   (progn
     (setvar 'clayer *OldClayer*)
     (setq *OldClayer* nil)
     )
   )
 (princ)
 )
;;					;;
;;					;;
(defun CommandReactor:CommandBroken (rea cmd)
 (if (and *OldClayer*
          (tblsearch "LAYER" *OldClayer*)
          )
   (progn
     (setvar 'clayer *OldClayer*)
     (setq *OldClayer* nil)
     )
   )
 (princ)
 )
;;					;;
;;					;;
(defun CommandReactor:CommandWillStart (rea cmd / lay new name)
 (if
   (and (wcmatch (strcase (car cmd)) "*DIM*")
        (setq *OldClayer* (getvar 'clayer))
        (progn
          (while (not (and (setq lay
                                  (getint
                                    "\nInput the DIM layer: Dim. (1), Dim. front (2): "
                                    )
                                 )
                           (< 0 lay 3)
                           )
                      )
            (alert "\nNumber must be (1) or (2):")
            )
          lay
          )
        (setq
          new (vla-add (vla-get-layers
                         (vla-get-activedocument (vlax-get-acad-object))
                         )
                       (if (eq lay 1)
                         (setq name "S-DIMENSIONS")
                         (setq name "S-DIMENSIONS front")
                         )
                       )
          )
        )
    (progn
      (vla-put-color new AcGreen)
      (setvar 'clayer name)
      )
    )
 (princ)
 )
;;					;;
(c:CommandReactorStart)
(princ "\nType CommandReactorStart activate the reactor and CommandReactorEnd to Deactivate")

Share this post


Link to post
Share on other sites
DesmetMartin

@Tharwat

 

First of all, thank you! This is exactly what I was looking for. :)

 

Second, what do you mean by that this is not a good way?

What would you suggest than? :)

 

Thanks again!

 

@Marko_Ribar

Also thanks! But there is a small issue when you do the continious command.

 

 

Kind Regards!

Share this post


Link to post
Share on other sites
Tharwat
@Tharwat

 

First of all, thank you! This is exactly what I was looking for. :)

 

Excellent, you are most welcome. :)

 

Second, what do you mean by that this is not a good way?

What would you suggest than? :)

 

In my opinion it is the best choice to let reactors do the job behind scenes without any intervention from users, but in your case you are interrupting the function to ask the user about a keyword which represents a layer name.

 

So alternatively you can just write a simple routine asking the user to specify three points if you creating DimLinear or DimAligned then you can use the same way you asked the user to specify number 1 or 2 for your layer name and reactor is not needed at all.

 

As you might know the command name: dimstyle has a short keyword to call this command which is d so run my posted codes above and hit d and the reactor would be trigger and asks you to specify a number 1 or 2. so this is another issue to go with a simple routine than a reactor unless you modify the complete command name into reactors' codes.

 

 

Are you the one who wrote these codes in your first post ?

 

Happy coding.

Share this post


Link to post
Share on other sites
DesmetMartin

No, I did not wrote the codes in my first post.

I found this somewhere on the internet.

 

I'm trying to understand what you are saying, but I'm planning on taking lessons to learn to write LISP or vb.net so than I will understand I hope :P

 

Can I just ask you what I should do if I wanted to add another number with another layer attached to it?

 

 

Thanks!

Share this post


Link to post
Share on other sites
Tharwat

Can i ask you first what kind of dimensions you are creating?

Adding a number is not that difficult to add but I am planning to change your the reactor codes with another simple routine.

 

Did you try to hit d when you run the codes I posted above ? and what message did you receive ?

Share this post


Link to post
Share on other sites
DesmetMartin

In the plan's I make, I need a lot of different layers and dimstyles.

 

This is why it is usefull to get the question of the layers.

The dimstyles I adapt myself when needed.

 

The message I got was "Input the DIM layer: ...."

Share this post


Link to post
Share on other sites
Tharwat

Are you making Linear or Aligned dimensions or anything else ? list them if not too much.

 

You did not get my point. run my codes then write at the command line in AutoCAD d and hit enter.

Share this post


Link to post
Share on other sites
DesmetMartin

I use mostly Linear, Aligned, continius, diameter, radius and angular.

(So the most common things).

 

This is what I get when running the 'd' command.

D-command.jpg

 

Sorry if its hard to communicate, I'm doing my best.:( :)

Share this post


Link to post
Share on other sites
Tharwat

Sorry if its hard to communicate, I'm doing my best.:( :)

No worries , you are doing just great. :)

 

I was thinking to write a program away from reactors but since that you use almost all types of Dimensions, you can keep using the same codes I posted earlier.

 

Regarding to your question about adding a new number with a new layer, can you clarify the inputs you want to add to allow me to modify the codes?

Share this post


Link to post
Share on other sites
DesmetMartin

Ok, you are helping me so great!

You should see me smile :shock: :D

 

I would still need to have a layer "S-DIMENSIONS Top" on number 3 (Dim. Top).

and then a layer "S-DIMENSIONS Detail" on number 4 (Dim. Detail).

 

 

Thanks again! :D

Share this post


Link to post
Share on other sites
Tharwat

Try this with the four options and let me know.

 

(vl-load-com)
;;	Author: Tharwat Al Shoufi	;;
;;	Date: 09.May.2016		;;
(defun c:CommandReactorStart nil
 (or *CommandReactor*
     (setq *CommandReactor*
            (vlr-command-reactor
              nil
              '(
                (:vlr-commandcancelled . CommandReactor:CommandBroken)
                (:vlr-commandended . CommandReactor:CommandEnded)
                (:vlr-commandfailed . CommandReactor:CommandBroken)
                (:vlr-commandwillstart . CommandReactor:CommandWillStart)
               )
            )
     )
 )
 (prompt "\nCommand reactor Started.")
 (princ)
)
;;					;;
;;					;;
(defun c:CommandReactorEnd nil
 (if *CommandReactor*
  (progn
   (vlr-remove *CommandReactor*)
   (setq *CommandReactor* nil))
 )
 (prompt "\nCommand reactor Disabled !")
 (princ)
)
;;					;;
;;					;;
(defun CommandReactor:CommandEnded (rea cmd)
 (if (and *OldClayer*
          (tblsearch "LAYER" *OldClayer*)
          (wcmatch (strcase (car cmd)) "*DIM*")
     )
   (progn
     (setvar 'clayer *OldClayer*)
     (setq *OldClayer* nil)
   )
 )
 (princ)
)
;;					;;
;;					;;
(defun CommandReactor:CommandBroken (rea cmd)
 (if (and *OldClayer*
          (tblsearch "LAYER" *OldClayer*)
     )
   (progn
     (setvar 'clayer *OldClayer*)
     (setq *OldClayer* nil)
   )
 )
 (princ)
)
;;					;;
;;					;;
(defun CommandReactor:CommandWillStart (rea cmd / lay new name)
 (if
   (and (not (eq (strcase (car cmd)) "DIMSTYLE"))
         (wcmatch (strcase (car cmd)) "*DIM*")
        (setq *OldClayer* (getvar 'clayer))
        (progn
          (while (not (and (setq lay
                                  (getint
                                    "\nInput the DIM layer: Dim.(1), Front(2), Top (3), Detail(4): "
                                  )
                           )
                           (< 0 lay 5)
                      )
                 )
            (alert "\nNumber must be betwee [1,2,3 or 4]:")
          )
          lay
        )
   )
    (progn
      (cond (*AcadLayers*)
            ((setq *AcadLayers*
                    (vla-get-layers
                      (vla-get-activedocument
                        (vlax-get-acad-object)
                      )
                    )
             )
            )
      )
      (if (not (tblsearch "LAYER"
                          (setq name (nth (1- lay)
                                          '("S-DIMENSIONS"
                                            "S-DIMENSIONS front"
                                            "S-DIMENSIONS Top"
                                            "S-DIMENSIONS Detail"
                                           )
                                     )
                          )
               )
          )
        (progn
          (setq new (vla-add *AcadLayers* name))
          (vla-put-color new AcGreen)
        )
      )
      (setvar 'clayer name)
    )
 )
 (princ)
)
;;					;;
(c:CommandReactorStart)
(princ
 "\nType CommandReactorStart to activate the reactor and CommandReactorEnd to Deactivate"
)

Edited by Tharwat

Share this post


Link to post
Share on other sites
DesmetMartin

It works great!

Thanks!

 

There is only 1 'problem'.

When you enter 'commandreactorEND' it stops like it should do.

But when you then enter 'commandreactorSTART' it doens't work anymore?

 

It would be cool if you could turn it on and off whenever you wanted it.

 

You helped me big time!

Thank you so much!

I really really appreciate what you did!

 

Thanks again!

Share this post


Link to post
Share on other sites
Tharwat

Yes you are right, I forgot to set the variable that represents the reactor to nil.

 

Codes modified above so try again on a new drawing.

Share this post


Link to post
Share on other sites
DesmetMartin

Alright!

 

Now it work :)

 

There still is something but it's probably hard to fix.

You don't have to do this, you helped me already this much.

 

I've noticed that when you select another dimstyle, it doens't change.

You have to select the DIM and change the dimstyle when placed.

 

If you know what I mean? :P

Share this post


Link to post
Share on other sites
Tharwat

Happy to help :)

 

What do you mean by select another DimStyle and it does not change?

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...