Jump to content

Recommended Posts

Posted

Hi guys, I'm new to the boards. I was wondering if you could help me. I have never used LISP's before and i think I'm in need to use one.

 

Here's my problem,

 

I have complied a series of commands in microsoft excel (to later copy to the command line in CAD) to quickly select and zoom to specific parts of my drawing, draw a viewport around it and import it to a specific layout tab. The problem i have is that my viewport is always in the bottom left hand corner of my layout page. Is there something I can do to select a viewport in Pspace and move it (from its center) to a specific coordinate on my layout, using only commands. i.e without any user input from the mouse.

 

it would be great if some one could help

 

many thanks

 

lee

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    18

  • Lee5150

    9

  • SteveK

    7

Top Posters In This Topic

Posted Images

Posted

Firstly, welcome to the forums Lee, I'm sure you'll like it here :)

 

I think you could use the vla-put-center method on the viewport object to move it to the correct position.

 

I am not sure what you have so far though, so can't really advise much more than that.

 

Lee

Posted

Hi, thanks for that,

 

As I said, I'm completely new to anything to do with LISP's. Is what you just gave me a command in CAD or something you would use in a LISP?

 

I think my previous post was a bit confusing.

 

I'll simplify it...

 

What I'm wanting to do is move a viewport (from its center) to a specific coordinate using only the keyboard, i.e commands that can be typed in. This is just so it looks neat went I send my drawings to clients.

 

thanks again

 

lee

Posted
Hi, thanks for that,

 

As I said, I'm completely new to anything to do with LISP's. Is what you just gave me a command in CAD or something you would use in a LISP?

 

I think my previous post was a bit confusing.

 

I'll simplify it...

 

What I'm wanting to do is move a viewport (from its center) to a specific coordinate using only the keyboard, i.e commands that can be typed in. This is just so it looks neat went I send my drawings to clients.

 

thanks again

 

lee

 

Sorry, vla-put-center is a LISP method - I would approach this problem using LISP.

 

But, using the keyboard only, if you didn't want to stray into LISP, this may be difficult imo.

 

Lee

Posted

As an example code:

 

(defun c:vpmove  (/ ent pt)
 (vl-load-com)
 (if (and (setq ent (car (entsel "\nSelect Viewport: ")))
          (eq "VIEWPORT" (cdr (assoc 0 (entget ent))))
          (setq pt (getpoint "\nSelect Point to move it to: ")))
   (vla-put-center
     (vlax-ename->vla-object ent)
       (vlax-3D-point pt)))
 (princ))

Posted

thanks again,

 

I know I probably seem a bit stupid but I have never used LISP's.

 

I use CAD everyday at work and I understand most things but not lisp's.

 

how do I make a lisp? I know there is some sort of editor within CAD but i've never had to use it.

 

lee

Posted

i am wanting to select the viewport using move and then picking 10,10 (to select the viewport)

then i need to select where to move it from (need this to be its center)

then i need to place it at 165.6,133.5

this will leave it in the middle of my companies titleblock.

Posted
thanks again,

 

I know I probably seem a bit stupid but I have never used LISP's.

 

I use CAD everyday at work and I understand most things but not lisp's.

 

how do I make a lisp? I know there is some sort of editor within CAD but i've never had to use it.

 

Not a problem.

 

Firstly, do you know how to load and run a LISP?

 

If not, there is a tutorial here

 

If there is anything you don't understand about that, just ask.

 

As for the writing side:

 

  • I would suggest using the Visual LISP Editor provided in ACAD, open it by typing VLIDE at the command line. Then go to "File" > "New File" and you can begin writing your code.

  • If you have never written a LISP before, I would suggest starting with just plain AutoLISP and get competent in that, before maybe moving onto Visual LISP, as this is a bit more involved.

If you need any help on this code, I'd be more than happy to lend a hand.

 

Lee

Posted
i am wanting to select the viewport using move and then picking 10,10 (to select the viewport)

 

then i need to select where to move it from (need this to be its center)

 

then i need to place it at 165.6,133.5

 

this will leave it in the middle of my companies titleblock.

 

This will put the center of the viewport at (165.6 133.5 0.0):

 

(defun c:vpmove  (/ ent)
 (vl-load-com)
 (if (and (setq ent (car (entsel "\nSelect Viewport: ")))
          (eq "VIEWPORT" (cdr (assoc 0 (entget ent)))))
   (vla-put-center
     (vlax-ename->vla-object ent)
       (vlax-3D-point '(165.6 133.5 0.))))
 (princ))

Posted

thank you very much!

 

so once the text is inserted into the lisp editor i then save it as a .lsp

and load it.

 

what do i then type to get the command to work?

 

will i need to select the viewport manually or can i do it using coordinates?

 

lee

Posted
thank you very much!

 

so once the text is inserted into the lisp editor i then save it as a .lsp

and load it.

 

what do i then type to get the command to work?

 

will i need to select the viewport manually or can i do it using coordinates?

 

lee

 

When the code is written in the Editor, you can load it straight from there, or save it as a .lsp and load it manually using "appload" at the command line.

 

In this case, type vpmove to activate the command - see the tutorial link I posted.

 

As for selecting the viewport, I can make a code that will let you select it using coords, but imo, it would be better to do the whole operation using LISP, instead of a mixture of commands from Excel. :wink:

 

Lee

Posted

Load it in the Editor using this button:

 

ex.jpg

 

Then run it with the syntax that appears after : (defun c:

Posted

i work for a furniture manufacturing company called british thornton.

 

i know i have gone the long way around but what i need to do is have individual rooms on layout tabs. i have done this by drawing a rectangle around the room in mspace. then i give the rectangle a group name. i use a series of commands written in excel to select and copy the group, pull it through into layout 1 in pspace, then make it into a viewport then zoom and scale to the original group (therefore zooming to that room) i copy and paste it into the command line from and it does it in seconds. but because i used copyclip to copy the rectangle in the first place, and the pasting it at 0,0 on my layout, the viewport is not in the center.

 

i tried the lisp and once iv selected the viewport, it doesn't move. :(

 

im sorry to mess you around

 

lee

Posted

Ok, I think that could all be done using LISP, but as you have got to this stage already, I think its best we carry on from here.

 

i tried the lisp and once iv selected the viewport, it doesn't move. :(

 

As for this, I tried the LISP on my machine, and the viewports is moved correctly. Is there any chance you could attach a sample drawing so that I could see whats wrong?

 

Lee

Posted

do you have an email address i could send the samples to because theyre too big to upload onto here?

 

thanks

 

lee

Posted

i figured out why the lisp didn't work. its because I'm using a viewport that is made from a polygon. i don't know if theres a way to do it with one of those.

 

lee

Posted
i figured out why the lisp didn't work. its because I'm using a viewport that is made from a polygon. i don't know if theres a way to do it with one of those.

 

lee

 

Ahh, yes that makes things slightly difficult. :(

 

I think you would have to find the centroid of the lwpolyline and then move it relative to that.

 

Lee

Posted

if you would like me to email you a sample of what i am trying to achieve i can do. maybe there is an easier way of doing it.

Posted

I would send you my email address, but I can't seem to send you a PM with it :(

  • 3 weeks later...
Posted

Hello,

 

I'm trying to do something similar with regards getting the center of the viewport:

I'm trying to modify the center of another viewport so that it has the same x co-ordinate as the other viewport. (And I'm also trying to do this is autolisp, not vlisp :)).

I was looking at the viewport entity and I'm guessing the viewport's center is at dxf code 12, so based on that (and I know it's not the best code layout but) here's what I've got:

(defun C:vp1 (/
         en1 enlst1 en1_cen_x
         en2 enlst2 en2_cen_x
         new_cen)

 (setq en1 (car(entsel))
   enlst1 (entget en1))

 (setq en2 (car(entsel))
   enlst2 (entget en2))
 
 (Cond ((eq (cdr (assoc 0 enlst1)) "VIEWPORT")
    (setq en1_cen_x (cadr (assoc 12 enlst1))))
   )

 (Cond ((eq (cdr (assoc 0 enlst2)) "VIEWPORT")
    (setq en2_cen_x (cadr (assoc 12 enlst2))))
   )

 (If (AND en1_cen_x en2_cen_x)
   (Progn
     (setq new_cen (list en1_cen_x (caddr (assoc 12 enlst2)) (cadddr (assoc 12 enlst2))))
     (entmod (subst (cons 12 new_cen) (assoc 12 enlst2) enlst2))
     )(princ "Either or Both selections are not Viewports")
   )

 (entupd en2)

 (princ)
 )

This doesn't work. It just doesn't change the dxf code 12.

Does anyone know what the problem is?

 

EDIT: on further investigation it appears DXF code 17 is the modelspace centerpoint I'm after. But changing from 12 to 17 still doesn't replace the x co-ordinate in the second viewport. Any help would be great thanks.

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