Jump to content

Lisp not work in model only layout


CAD

Recommended Posts

hello, i got a lisp that only work in layout who can modified it so i also can run in the model. thxxxxx

in the model it says:; error: bad argument type: lselsetp nil

 

 

(Defun c:vplk ()
(setq d (ssget "_x" '((0 . "VIEWPORT"))))
 	(vplock d T)(princ))

(Defun c:vpun ()
(setq d (ssget "_x" '((0 . "VIEWPORT"))))
 	(vplock d nil)
 	(princ)
 )

(Defun vplock (sel flg)
	(setq mode (if flg  :vlax-true :vlax-false))
(repeat (setq i (sslength sel))
	  (vlax-put-property (vlax-ename->vla-object (ssname sel (Setq i (1- i))))
	    'DisplayLocked mode)
  )
 	(princ (strcat "\nViewports " (if flg "" "Un" )  "locked"))(princ)
)				  
(vl-load-com)

Link to comment
Share on other sites

Hi,

An example.

(defun c:vplk (/ spc)
 (setq spc (getvar 'ctab))
 (foreach lay (layoutlist)
   (setvar 'ctab lay)
   (vplock (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 lay))) t)
 )
 (setvar 'ctab spc)
 (princ)
)

Link to comment
Share on other sites

Looking at the code in the OP the problem should only occurs in drawings without viewports.

 

To fix it try:

(defun c:vplk ( / d)
 (if (setq d (ssget "_X" '((0 . "VIEWPORT"))))
   (vplock d T)
 )
 (princ)
)

Link to comment
Share on other sites

both code not working error code

 

Command: VPLK

Restoring cached viewports - Regenerating layout.

; error: no function definition: VPLOCK

 

i use acad2016 can u also add function vpunlock

Link to comment
Share on other sites

yes

 

Command: VPLK

Restoring cached viewports - Regenerating layout.

; error: no function definition: VPLOCK

 

i use acad2016 can u also add function vpunlock

 

You need to load that function 'VPLOCK' along with the codes that I posted earlier since I re-wrote the function in another way that you can use it for the two options in the same manner you have posted in the first post.

Link to comment
Share on other sites

You need to load that function 'VPLOCK' along with the codes that I posted earlier since I re-wrote the function in another way that you can use it for the two options in the same manner you have posted in the first post.

 

YESs thankyou when i combine it works fine!!!

Link to comment
Share on other sites

Looking at the code in the OP the problem should only occurs in drawings without viewports.

 

To fix it try:

(defun c:vplk ( / d)
 (if (setq d (ssget "_X" '((0 . "VIEWPORT"))))
   (vplock d T)
 )
 (princ)
)

 

Roy your code not working when i combine it?

 

 

 

(Defun c:vplk ()
(setq d (ssget "_x" '((0 . "VIEWPORT"))))
 	(vplock d T)(princ))

(Defun c:vpun ()
(setq d (ssget "_x" '((0 . "VIEWPORT"))))
 	(vplock d nil)
 	(princ)
 )

(Defun vplock (sel flg)
	(setq mode (if flg  :vlax-true :vlax-false))
(repeat (setq i (sslength sel))
	  (vlax-put-property (vlax-ename->vla-object (ssname sel (Setq i (1- i))))
	    'DisplayLocked mode)
  )
 	(princ (strcat "\nViewports " (if flg "" "Un" )  "locked"))(princ)
)				  
(vl-load-com)

(defun c:vplk ( / d)
 (if (setq d (ssget "_X" '((0 . "VIEWPORT"))))
   (vplock d T)
 )
 (princ)
)

Link to comment
Share on other sites

@CAD:

The code works fine.

 

I suspect you do not realise that when a layout has never been activated it does not contain any viewports. The viewport you see when you first activate a layout has been newly created (which is why it can be an exact fit for the entities that are currently visible in model space).

So if you start a drawing from scratch, for example, and you are still on the "Model" tab, there will be no viewports in the drawing for the code to change.

 

Please retest the code in a drawing where all layouts have been activated.

 

Note 1:

When combining the code you should remove old versions of functions instead of just appending new code.

 

Note 2:

When a layout is first activated not one but two viewports are automatically generated. The first is the main paper space viewport.

Edited by Roy_043
Link to comment
Share on other sites

@CAD:

The code works fine.

 

I suspect you do not realise that when a layout has never been activated it does not contain any viewports. The viewport you see when you first activate a layout has been newly created (which is why it can be an exact fit for the entities that are currently visible in model space).

So if you start a drawing from scratch, for example, and you are still on the "Model" tab, there will be no viewports in the drawing for the code to change.

 

Please retest the code in a drawing where all layouts have been activated.

 

Note 1:

When combining the code you should remove old versions of functions instead of just appending new code.

 

Note 2:

When a layout is first activated not one but two viewports are automatically generated. The first is the main paper space viewport.

 

hELLO Roy_043 u right!!!:):notworthy: i think i made a mistake the lisp also WORKS!!great. thinks some old code was in mine acad.

 

u both areee good!!!!thankksss Bedankt!!!

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