Jump to content

Recommended Posts

Posted

Hello Everyone,

 

I have done simple lisp before but I think I stepped in over my head with this one.

 

I want to change to correct layer, attach xref, change back to previous layer then zoom extents. I got the following code:

 

; This function attaches xref on  correct layer
;
( DEFUN C:XRA 
()
;(SETQ CURRENTLAYER (GETVAR  "CLAYER"))
(SETVAR "CLAYER" 
"g-anno-refr")
(initdia)
(command  "._xref")
(princ)
;(SETVAR 
"CLAYER" CURRENTLAYER)
)

 

Setting the layer is not setup to function because it wasn't working.

 

I had some other code in but it wasn't working at all, so I removed it.

 

At work everyone forgets to set layer for ref's and I am trying to solve the problem.

 

Any help greatly appreciated.

 

Jim C.

AutoCad Civil 3D 2011

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • JWC

    11

  • Lee Mac

    10

  • rkent

    2

  • Tharwat

    1

Popular Days

Top Posters In This Topic

Posted

Hi Jim, welcome to CADTutor :beer:

 

You might be interested in this program of mine:

 

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

 

It will use reactors to automatically set the correct layer (creating the layer if it doesn't exist) when using certain commands, then reset the layer after the command has been used.

 

This way means there is no need to override in-built commands, or train users to use custom commands.

 

Lee

Posted

Thanks Lee....Seems to be what I am looking for. How woudl I modify to make just do what I am needing? Don't want to give to much to get messed up.

 

I am thanksful for your help.

 

Jim C

Posted

Hi Jim,

 

Just change the *LayerData* section at the top of the code to:

 

  (setq *LayerData*
  '(
     ("*XATTACH" "g-anno-refr" 7)
   )
 )

 

(You can change the '7' to the colour of your layer also).

Posted

Hi Lee,

 

I was trying the LayerDirector.lsp and I keep getting this error message, the error appears on every command name whether defined in the lsp or not.

 

Command: TEXT

; error: no function definition: VL-

Current text style: "Standard" Text height: 0'-0 1/2" Annotative: No

Specify start point of text or [Justify/Style]: *Cancel*

 

Any ideas on what I am doing wrong?

 

Thanks,

rkent

Posted

Hi rkent,

 

I've just tested the code as it stands on my site and I can't seem to replicate the error you are receiving; judging by the error message, it looks as though there has been a space added mid-way between a Visual LISP function, i.e. (vl- load-com) perhaps, so the (vl- is being interpreted as a function in itself.

 

Could you perhaps re-download / re-load the program to confirm whether the error persists?

 

Cheers,

 

Lee

Posted

Lee,

Thanks for your help and quick response with this.....I have been pounding my head for days on this. You have helped greatly.

 

Jim C

Posted
Lee,

Thanks for your help and quick response with this.....I have been pounding my head for days on this. You have helped greatly.

 

Jim C

 

You're very welcome Jim, happy to help :)

Posted

Lee,

I wanted to make creating a viewport do the same but it is not working. Here is what I have.

 


(setq *LayerData*
  '(
     
("*XATTACH" "g-anno-refr" 7)
     ("_+vports" 
"g-psvw" 251)
   )
 )

Posted

Hi Jim,

 

Change it to:

 

  (setq *LayerData*
  '(
    ("*XATTACH" "g-anno-refr" 7)
    ("*VPORT*"  "g-psvw"    251)
   )
 )

And be sure to re-load the LISP function to implement the changes.

 

I should have mentioned somewhere in the code or on my site that the command should be capitalised.

Posted
Hi rkent,

 

I've just tested the code as it stands on my site and I can't seem to replicate the error you are receiving; judging by the error message, it looks as though there has been a space added mid-way between a Visual LISP function, i.e. (vl- load-com) perhaps, so the (vl- is being interpreted as a function in itself.

 

Could you perhaps re-download / re-load the program to confirm whether the error persists?

 

Cheers,

 

Lee

 

Lee,

 

The text editor I use is breaking the lines so a few of the strings were broken to the next line. All is good now, thanks very much for your continued generosity.

 

I am going to try getting it to work for xrefs but I may be back if I can't figure it out. Got it, I used "*XATT*".

 

rkent

Posted

Thanks again Lee....This is EXACTLY what I was looking for....Wish I had a better understanding of writing LISP.

 

Jim C

Posted

 

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

 

It will use reactors to automatically set the correct layer (creating the layer if it doesn't exist) when using certain commands, then reset the layer after the command has been used.

 

This way means there is no need to override in-built commands, or train users to use custom commands.

 

Lee

 

It works nice here , and very smooth creation of the layer .

 

Lee , is there any start point that I should start from with Reactors ?

 

Thanks a lot

Posted
Lee,

 

The text editor I use is breaking the lines so a few of the strings were broken to the next line. All is good now, thanks very much for your continued generosity.

 

I am going to try getting it to work for xrefs but I may be back if I can't figure it out. Got it, I used "*XATT*".

 

Excellent, glad to hear you have it working now rkent - shout if you need any more help with it :)

 

Thanks again Lee....This is EXACTLY what I was looking for....Wish I had a better understanding of writing LISP.

 

Good stuff Jim, you're welcome - it certainly makes for more consistent drawings when you don't have to worry about setting the correct layer :)

 

It works nice here , and very smooth creation of the layer .

 

Lee , is there any start point that I should start from with Reactors ?

 

Thanks a lot

 

Thank you for testing it Tharwat :)

 

Reactors are considered a more advanced area of Visual LISP as you have to ensure your coding is rock-solid and account for every eventuality. Maybe have a look at this thread at theSwamp:

 

http://www.theswamp.org/index.php?topic=39052

Posted

Lee,

Is there a way to make it zoom extents on just the xref attachment? If so this would be a perfectly what I need. it is still GREAT. Thanks again for your help.

 

Jim C.

Posted
Lee,

Is there a way to make it zoom extents on just the xref attachment? If so this would be a perfectly what I need. it is still GREAT. Thanks again for your help.

 

Sure, at Line 123 in the original code, add this:

 

      (if (wcmatch (strcase (car params)) "*XATTACH")
         (vla-zoomextents (vlax-get-acad-object))
     )

 

So that section would look like this:

 

    (progn
     (setvar 'CLAYER *oldlayer*)
     (setq *oldlayer* nil)
     (if (wcmatch (strcase (car params)) "*XATTACH")
         (vla-zoomextents (vlax-get-acad-object))
     )
   )

Posted
Lee,

Is there a way to make it zoom extents on just the xref attachment? If so this would be a perfectly what I need. it is still GREAT. Thanks again for your help.

 

Sorry, do you mean before or after the XRef is attached?

 

My above mod assumes after.

Posted

Sorry about that Lee....After the xref is attached I would like it to zoom extents.

 

Thanks,

Jim C.

Posted

Lee,

I am getting an error after after I added.

 

(defun LayerDirectorReset ( reactor params ) (vl-load-com)
 (if
   (and (not (wcmatch (strcase (car params)) "*UNDO")) *oldlayer* (tblsearch "LAYER" *oldlayer*)
     (zerop
       (logand 1
         (cdr
           (assoc 70
             (tblsearch "LAYER" *oldlayer*)
           )
         )
       )
     )
   )
   (progn
     (setvar 'CLAYER *oldlayer*)
     (setq *oldlayer* nil)
     (if (wcmatch (strcase (car params)) "*XATTACH")
         (vla-zoomextents (vlax-get-acad-object))
     )
   )
)

Posted

You are missing the last part of the function - what is up with the formatting also?

 

Here is the replacement function:

 

(defun LayerDirectorReset ( reactor params ) (vl-load-com)
 (if
   (and (not (wcmatch (strcase (car params)) "*UNDO")) *oldlayer* (tblsearch "LAYER" *oldlayer*)
     (zerop
       (logand 1
         (cdr
           (assoc 70
             (tblsearch "LAYER" *oldlayer*)
           )
         )
       )
     )
   )
   (progn
     (setvar 'CLAYER *oldlayer*)
     (setq *oldlayer* nil)
     (if (wcmatch (strcase (car params)) "*XATTACH")
         (vla-zoomextents (vlax-get-acad-object))
     )
   )
 )  
 (princ)
)

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