Jump to content

Select model space object from viewport


aridzv

Recommended Posts

Hi.

I have a lisp that get an attribute value from a block and put this value to a Mleader - all in model space.

I need to be able to select that block when in paper space from a viewport (the block is visible - click on it) ,get it's attribute values and use them in paper space.

the question is - can I click on the object in paper space,make the lisp to get the object properties and use them back in the viewport.

I've googled this but could'nt get quite what I need.

here is a sample drawing and the lisp I use in model space.

 

thanks,

aridzv.

 

*EDIT:

in my google search I fount this old thread that mybe can be a start for more talented programmers than me...

 

MLeaderWBlTxt.lspDrawing1.dwg

Edited by aridzv
Link to comment
Share on other sites

If you pick a point in paperspace you can go to model space and using a trans function work out where the point is in Model and then try using (ssget pt). Yes does work.

 

Look up help about trans function. 

 

(trans pt 3 0)

 

  • Like 1
Link to comment
Share on other sites

39 minutes ago, BIGAL said:

If you pick a point in paperspace you can go to model space and using a trans function work out where the point is in Model and then try using (ssget pt). Yes does work.

 

Look up help about trans function. 

 

(trans pt 3 0)

 

 

I wrote this:

(defun c:test3 ( / pt pt1)
(setq pt (getpoint)) ;;get point in paper space
(setq pt1 (trans pt 3 0))
(command "._MSPACE")
(command "Point" pt1)
)

 

it dosn't put the point exactelly in place.

in paper space I snap to node on the object and the point is located in some offset...

Link to comment
Share on other sites

3 hours ago, BIGAL said:

Is you model space in a non World UCS ?

 

no.

it is a 3d drawing and it happens when the view is any 3d view (Top Front Right,Top Back Right,etc...).

 

Link to comment
Share on other sites

solved by @Steven P here - thanks.

 

(defun c:test3 ( / e)
  (getpoint);; get point in paper space on the target object
  (command "._MSPACE");; move to model space with the currsor "Locked" on the selected point on the target object
  (setq e (car (last (nentselp (cadr (grread t))))));; get the entity name by the point located on the target object
  (command "._PSPACE");; back to paper space
  (princ e);; print the entity name
  (entget e);; print the entity data
)

 

Edited by aridzv
Link to comment
Share on other sites

Posted (edited)

another way,

Maybe cleaner.

(defun c:test33 ( / pt ss entname)
  (getpoint) ;;get point in paper space on the target object
  (command "._MSPACE");;move to model space with the currsor "Locked" on the selected point on the target object
  (setq pt (cadr (grread t)));;get the point where the currser is - "Locked" on the target object
  (setq ss (ssget pt));; use ssget at point to get selection set with the target object
  (setq entname(ssname ss 0));; get the entity name from the selection set (the first one in the selection set)
  (command "._PSPACE");;back to paper space
  (princ entname);;print the entity name
  (entget entname);; print the entity data
)

 

Edited by aridzv
Link to comment
Share on other sites

On 2/24/2024 at 11:39 PM, BIGAL said:

If you pick a point in paperspace you can go to model space and using a trans function work out where the point is in Model and then try using (ssget pt). Yes does work.

 

Look up help about trans function. 

 

(trans pt 3 0)

 

 

it bug's me why it didnn't work,

so after some digging I found that it had to be done in tow steps this way:

(setq ptps(getpoint)) ;;get point in paper space 
(setq ptps1 (trans ptps 3 2)) ;Step 1: translate the point from the Paper space DCS (Display Coordinate System) to the DCS of the current model space viewport.
(setq ptms (trans ptps1 2 0)) ;Step 2: translate the point from the DCS of the current model space viewport to World (WCS)

;;;;;;
;; can also be in one code line this way: (setq ptms(trans(trans ptps 3 2) 2 0)) 
;;;;;;

 

and used this way in the code:

(defun c:test33B ( / ptps ptms ss entname)
  (setq ptps(getpoint) ;;get point in paper space on the target object
  (setq ptms(trans (trans ptps 3 2) 2 0));; translate the point from paper space to model space.
  (command "._MSPACE");;move to model space with the model space point on the target object
  (setq ss (ssget ptms));; use ssget at point to get selection set with the target object
  (setq entname(ssname ss 0));; get the entity name from the selection set (the first one in the selection set)
  (command "._PSPACE");;back to paper space
  (princ entname);;print the entity name
  (entget entname);; print the entity data
)

 

aridzv.

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