Jump to content

Lisp and viewport positioning


DVDM

Recommended Posts

Hi all,

I’m currently working on a set of lisp routines to make life a bit easier, and help us out with some of the more mundane tasks in Autocad. Unfortunately, my lisp knowledge is quite limited. While I can edit existing code to a certain extent, or implement other lisp routines within my own, my own routines are no more than a simple macro really; a succession of commands and predefined parameters.

I would like to expand the following routine to include a few automated steps:

(defun C:Y180 ()

(command "ucs" "y" "180")

(command "plan" "c")

)

As you can tell from the code, I want to look at my model from the opposite side through the viewport.

The problem is though, that after the “plan” “c” command, it does a zoom extents, whereas I would like to simply return to the very same scale factor and position within the viewport I had originally. (I found a lisp routine that takes care of the unlocking/locking of the viewport before and after, which i'm planning on using)

It’d be great if LISP can take care of this, but I don’t know how. For starters, I don’t know where to get the parameters that define the view (center X, center Y, center Z, Height, Width), if they can be read at all (in the properties panel of the viewport these parameters are grayed out and non-editable).

Once I know that, I guess there should be a way to read and store those parameters before doing the "ucs" and "plan" commands, then afterwards reapplying them to the viewport.

Because these centerXYZ/height/width parameters basically define the scale as well, I don’t think there would be a need to read the viewport scale somewhere in the routine.

Ultimately, it would be ideal if I could just select all the viewports I would want to give this treatment, and do them in one hit (some layouts have up to 20 viewports), but I’m afraid I’m thinking way ahead of myself here. Doing it on a one by one basis would be wonderful already.

Am I thinking in the right direction here, and does anyone have any suggestions?

Link to comment
Share on other sites

I think I would approach it like this

 

[b][color=BLACK]([/color][/b]setq vc [b][color=FUCHSIA]([/color][/b]getvar [color=#2f4f4f]"VIEWCTR"[/color][b][color=FUCHSIA])[/color][/b]
     vs [b][color=FUCHSIA]([/color][/b]getvar [color=#2f4f4f]"VIEWSIZE"[/color][b][color=FUCHSIA])[/color][/b]
     ve [b][color=FUCHSIA]([/color][/b]trans '[b][color=NAVY]([/color][/b]0 0 1[b][color=NAVY])[/color][/b] 0 1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
[b][color=BLACK]([/color][/b]command [color=#2f4f4f]"_.UCS"[/color] [color=#2f4f4f]"_Y"[/color] 180
        [color=#2f4f4f]"_.UCS"[/color] [color=#2f4f4f]"_V"[/color]
        [color=#2f4f4f]"_.ZOOM"[/color] [color=#2f4f4f]"_C"[/color] [b][color=FUCHSIA]([/color][/b]trans vc ve 1[b][color=FUCHSIA])[/color][/b] vs[b][color=BLACK])[/color][/b]

This still needs a bunch of tweaking. -David

Link to comment
Share on other sites

Thanks David,

I will give that a try first thing on monday.

 

Can I ask, what's the significance of the '_.' in front of commands and '_' in front of the input? Without it seems to work just fine as well right? (in the little routine I wrote anyway)

I'm aware of the difference a '-' can make to the command line (i.e. PURGE and -PURGE), but this is new to me.

Link to comment
Share on other sites

From VLisp Help A2K

 


If you develop AutoLISP programs that can be used with a foreign language
version of AutoCAD, the standard AutoCAD commands and keywords are
automatically translated if you precede each command or keyword with an
underscore (_).

(command "_line" pt1 pt2 pt3 "_c")

If you are using the dot prefix (to avoid using redefined commands), you can
place the dot and underscore in either order. Both "._line" and "_.line"
are valid. 

-David

Link to comment
Share on other sites

Thanks David,

I will give that a try first thing on monday.

 

Can I ask, what's the significance of the '_.' in front of commands and '_' in front of the input? Without it seems to work just fine as well right? (in the little routine I wrote anyway)

I'm aware of the difference a '-' can make to the command line (i.e. PURGE and -PURGE), but this is new to me.

 

I had the same inquiry a while back - see here:

 

http://www.cadtutor.net/forum/showthread.php?t=26776

Link to comment
Share on other sites

Alright, Monday, back at work.

 

I tried the routine but it seemed to do nothing. Then I changed the "_.UCS" "_V" bit to "_.PLAN" "_C", and it worked on the test viewport I had made.

 

(defun C:TEST (/ vc vs ve)
(setq vc (getvar "VIEWCTR")
     vs (getvar "VIEWSIZE")
     ve (trans '(0 0 1) 0 1))
(command "_.UCS" "_Y" 180
        "_.PLAN" "_C"
        "_.ZOOM" "_C" (trans vc ve 1) vs)
)

 

I then opened an actual file on which this routine would be used, and discovered it didn't work as hoped.

The problem seems to be that it only works in viewports where Plan is set to World, and UCS is set to Plan.

 

Unfortunately, the majority of parts that we detail are laid out in model space in their actual position in this World.

In the file attached there are two parts (75x10mm equal angles). Note how they are dimensioned in model space, and shown in the viewports in the layout. If I run the routine on these viewports, I end up somewhere completely different (with View X and View Y coordinates swapped around), although at the correct scale.

If I run through the routine 8 times in the Stiffener R5 viewport, I end up at my original position again (no such luck in the Stiffener L5 viewport though, which has the UCS rotated 180deg around Z already).

It must have something to do with the matrix modification that occurs in the routine, but I'm not sure how that works.

Technically, all you would want to happen is the View X coordinate to change from + to - (or vice versa), as happens correctly in the mid-left viewport (with dimension '853 @ 0deg').

 

It was interesting to read what the '_.' means. I guess it would be good practice to incorporate that in all routines, although here internally it wouldn't make a difference (for most, even a pgp file modification is too complicated).

TEST.dwg

Link to comment
Share on other sites

David,

 

in your code, wouldn't the first Trans return a 3D point - if so, how can this be used in the second trans as one of the arguments?

 

(defun C:TEST (/ vc vs ve)
(setq vc (getvar "VIEWCTR")
     vs (getvar "VIEWSIZE")
  [i]  [color=Red][b] ve (trans '(0 0 1) 0 1))[/b][/color][/i]
(command "_.UCS" "_Y" 180
        "_.PLAN" "_C"
        "_.ZOOM" "_C" [i][b](trans vc [color=Red]ve[/color] 1)[/b] [/i]vs)
)

Link to comment
Share on other sites

Sorry for my ignorant question - just read the ACAD help:

 

An integer code, entity name, or 3D extrusion vector identifying the coordinate system in which pt is expressed. The integer code can be one of the following:

0 World (WCS)

1 User (current UCS)

2 If used with code 0 or 1, this indicates the Display Coordinate System (DCS) of the current viewport. When used with code 3, it indicates the DCS of the current model space viewport.

3 Paper space DCS (used only with code 2)

Me being a moron :P
Link to comment
Share on other sites

Looks like you have UCSVIEW set to 1 and the UCSs are saved with each viewport. This is something that I am not familiar with ( it didn't exist in R12 ). Also it looks like rotated Z axis UCSs. They are always a bear to deal with.

 

I don't know of a way to deal with these. Sorry. -David

Link to comment
Share on other sites

Thanks David, I appreciate your help.

This is what I cut 'n pasted the routine into for now:

 

 
(defun C:TEST (/ vc vs ve)
(setq vc (getvar "VIEWCTR")
vs (getvar "VIEWSIZE")
ve (trans '(0 0 1) 0 1))
(command "_.VPORTS" "_L" "_OFF" "_ALL" "")
(command "_.UCS" "_Y" 180
"_.PLAN" "_C"
"_.ZOOM" "_C" (trans vc ve 1) vs)
(command "_.VPORTS" "_L" "_ON" "_ALL" "")
(princ)
)

 

It works really well, as long as Plan and UCS are set to world. It will definately be of use to us this way.

I do think the problem can be solved, but I need to know a lot more about that 'trans' function before I can tackle that. That bit of code you supplied is still a bit of a mystery to me I must admit :)

Link to comment
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
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...