is it possible to access model space object properties from paper space?

aridzv
edited February 24 in LISP Codes
Hi.
I have a lisp that create a multileader with block attribute value in model space -
the lisp prompt the user to select a block and to choose the attribute from where to get the value for the multi leader text (see attached lisp and sample drawing).
is it possible to use it in paper space for the model space objects WITH OUT DUOBLE CLICK ON THE MVIEW AND GET INSIDE THE MODEL SPACE?
I know that model space object snaps are accessible in paper space,
so is there a way to access other properties as well?

Thanks,
aridzv.

Comments

  • Depending on the desired result, you might create a solution using the (trans) function.
    Also, (vla-TranslateCoordinates) could be used to convert coordinates from paper space to model space.

    This is just a general idea, I don't have an explicit solution.

    The overall workflow could be like this, assuming the paper space is active:
    - Click in a layout viewport.
    - Use that point to get the viewport under the point.
    - Set that viewport active - this can be done with using the dxf code 68, I am not sure about the (vla-) approach.
    - Translate the point to model space.
    - Add the mleader to the model space using the translated point as reference.
  • aridzv
    edited February 24
    @Virgil
    thanks for the reply.
    I searched for those ideas but could't find anything concreete...
    I can first get the viewport object using this code:
    (setq vpobj(ssget "_+.:S:E:L" '((0 . "VIEWPORT"))))
    then select a point on that viewport and convert it to vlax-3D-point by this code:
    (setq acadObj (vlax-get-acad-object))
    
    (setq adoc (vla-get-ActiveDocument acadObj))
             
    (setq pt (getpoint "\nSpecify a point :"))
    
    (setq pt1 (vlax-3D-point pt))

    but I can't find how to use the (vla-TranslateCoordinates) to get the model space point...

    Thanks,
    aridzv.
  • Look at your other post, was it Cadtutor forum.
  • @ALANH
    thanks.

    following your response I used this code over there:
    (defun c:test3 ( / pt pt1)
    (setq pt (getpoint)) ;;get point in paper space
    (setq pt1 (trans pt 3 0))
    (command "._MSPACE")
    (command "Point" pt1)
    )
    thanks,
    aridzv.
  • Hi,

    you can do this with Python wrappers
    https://github.com/CEXT-Dan/PyRx

    A sample might look like:

    import traceback
    from pyrx_imp import Rx
    from pyrx_imp import Ge
    from pyrx_imp import Gi
    from pyrx_imp import Db
    from pyrx_imp import Ap
    from pyrx_imp import Ed

    def PyRxCmd_doit() -> None:
    try:
    uTransSpaceFlag = 1
    eres = Ed.Editor.nEntSelPEx("\nPick model ent", uTransSpaceFlag)
    if eres[0] != Ed.PromptStatus.eOk:
    print("Oops {}: ".format(eres[0]))
    return

    ent = Db.Entity(eres[1])
    print("\nWooohoo, you selected a {}: ".format(ent.isA().dxfName()))
    print(eres)

    except Exception as err:
    traceback.print_exception(err)






  • @Its_Alive (Daniel),

    Am I correct in saying that only Bricscad BIM can use Python?
  • @Its_Alive (Daniel),

    Am I correct in saying that only Bricscad BIM can use Python?

    What I posted is a different project from what Bricsys includes in BIM, in fact it probably won’t work with BIM APIs.
    Basically, it wraps BRX & ActiveX for Python. So, I think BricsCAD V24 Pro for windows or better.

    Some links if your interested:
    https://pyarx.blogspot.com/
    https://github.com/CEXT-Dan/PyRx
    https://www.theswamp.org/index.php?board=76.0
    https://www.theswamp.org/index.php?topic=58162.0
  • @Its_Alive
    thanks,
    but I have no idea how to use it....
  • aridzv
    edited February 26
    solved in cadtutor...
    (defun c:test3 ( / e)
    (getpoint) ;;get point in paper space on the object
    (command "._MSPACE");; move to model space with the currsor "Locked" on the selected point on the object
    (setq e (car (last (nentselp (cadr (grread t))))));; get the entity name by the point located on the object
    (command "._PSPACE");; back to paper space
    (princ e);; print the entity name
    (entget e);; print the entity data
    )
  • different way,
    Maybe improved:
    (defun c:test33 ( / pt ss entname)
      (getpoint) ;;get point in paper space
      (command "._MSPACE")
      (setq pt (cadr (grread t)))
      (setq ss (ssget pt)) 
      (setq entname(ssname ss 0))
      (command "._PSPACE")
      (princ entname)
      (entget entname)
    )
  • aridzv
    edited March 3
    aridzv said:

    @ALANH
    thanks.

    following your response I used this code over there:

    (defun c:test3 ( / pt pt1)
    (setq pt (getpoint)) ;;get point in paper space
    (setq pt1 (trans pt 3 0))
    (command "._MSPACE")
    (command "Point" pt1)
    )
    thanks,
    aridzv.
    EDIT - The above trans didn't work...
    after some digging I found out that it can be done in two 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 the full lisp:
    (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
    )