Author Topic: How would one create a null ObjectId?  (Read 4635 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
How would one create a null ObjectId?
« on: September 08, 2010, 07:37:45 PM »
In a program I'm writing, I change the UCS of the drawing.  I'm doing it all without commands, so to change the UCS back I have to create one if the current UCS is un-named.  If you dump a document, you will see something like ' ;   ActiveUCS = AutoCAD: Null object ID ' if the UCS is un-named, and I would like to return it to that, but I can't seem to figure out how to do it.  Right now I create a temporary UCS for both the current, and the one I will be using ( if I was smarter, than I would just rotate the items with a transformation matrix, based on the normal of the object I'm selecting ), and then delete them, but I can't delete the one that is current ( which I switch back to, which is the reason I can't delete it ).

Any help is appreciated.  The code has been done here before, but didn't work in my situation, so hence the rewrite.  Will post when this is figured out, if people don't mind me doing so.

Thanks in advance.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: How would one create a null ObjectId?
« Reply #1 on: September 08, 2010, 10:58:52 PM »
Code: [Select]

 (setq *Obj (vlax-get-acad-object)
        *Doc (vla-get-activeDocument *Obj)
        *Uti (vla-get-Utility *Doc)
        *Ucs (vla-get-UserCoordinateSystems *Doc)
  )
  (if (= (getvar "UCSNAME") "")
    (progn
      (setq OldOrg (vla-GetVariable *Doc "UCSORG")
      OldXDr (vla-getVariable *Doc "UCSXDIR")
    OldYDr (vla-getVariable *Doc "UCSYDIR")
    OldUcs (vla-add *Ucs (vlax-3d-point '(0 0 0)) OldXDr OldYDr "OLDUCSTMP")
      )
      (vla-put-origin OldUcs OldOrg)
    )
    (setq OldUcs (vla-get-activeucs *Doc))
  )
  (Vla-Put-activeucs *Doc OldUcs)
« Last Edit: September 09, 2010, 04:52:26 AM by highflybird »
I am a bilingualist,Chinese and Chinglish.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How would one create a null ObjectId?
« Reply #2 on: September 09, 2010, 03:11:55 AM »
Code: [Select]
  XDir   (vla-TranslateCoordinates *Uti OldXDr acUCS acWorld 0)
  YDir   (vla-TranslateCoordinates *Uti OldYDr acUCS acWorld 0)
Aren't UCSXDIR and UCSYDIR already expressed in WCS?

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: How would one create a null ObjectId?
« Reply #3 on: September 09, 2010, 04:46:17 AM »
Code: [Select]
  XDir   (vla-TranslateCoordinates *Uti OldXDr acUCS acWorld 0)
  YDir   (vla-TranslateCoordinates *Uti OldYDr acUCS acWorld 0)
Aren't UCSXDIR and UCSYDIR already expressed in WCS?

you are right,I fixed it.
I am a bilingualist,Chinese and Chinglish.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How would one create a null ObjectId?
« Reply #4 on: September 09, 2010, 06:25:46 AM »
Tim,
The most satisfactory method for me is :

Create a UCS reflecting World named "_UCSWorld"

Create a dynamic UCS in the current UCS named "_UCSPrev"
Create a dynamic UCS for a working UCS named "_UCSWork"


Both can be created with the attached code ;
To name the current UCS
(setq  UCSPrevObj ( KDUB:UCS:BlackBox <NewUcsName> nil nil nil T) )

and to restore it
(vla-put-activeucs kglobal:activedoc UCSPrevObj )

If the current UCS is named I save it's Object in UCSPrevObj rather than create a new named UCS.



Code: [Select]

;;
;;;-------------------------------------------------------------
;;;-------------------------------------------------------------
;;
(defun kdub:ucs:blackbox (NewUcsName Origin XAxis YAxis Activate / objUCS)
                         ;|
   Code by Kerry Brown  2005.Jun.11
   Create a Named UCS and Optionally Activate it.

Required globals : kGlobal:activedoc kGlobal:ucss
Required dependancies : nil
Parameters  :-
NewUcsName :<string>
Origin :<PointList (X Y Z)>  in world
XAxis :<VectorList (X Y Z)> translated from world points
YAxis :<VectorList (X Y Z)> translated from world points
Activate :<nil or NonNil> Set as ActiveUCS

Returns : <VLA-OBJECT IAcadUCS ....>  or nil.

KDUB:UCS:BlackBox <NewUcsName> <Origin> <XAxis> <YAxis> <Activate>
All Vector parameter points shall be translated to world.
|;
;;;;----------------
  (or kglobal:activedoc
      (setq kglobal:activedoc (vla-get-activedocument (vlax-get-acad-object)))
  )
  (or kglobal:ucss
      (setq kglobal:ucss (vla-get-usercoordinatesystems kglobal:activedoc))
  )
  (or NewUcsName (setq NewUcsName "_UCSTemp"))
  (or Origin (setq Origin (getvar "ucsorg")))          ; 3D WCS coordinates
  (or XAxis (setq XAxis (getvar "ucsxdir")))           ; 3D WCS coordinates specifying a point on the positive X axis of the UCS
  (or YAxis (setq YAxis (getvar "ucsydir")))           ; 3D WCS coordinates specifying a point on the positive Y axis of the UCS.
  ;;
  (setq objUCS (vla-add kglobal:ucss
                        (vlax-3d-point '(0.0 0.0 0.0)) ;origin
                        (vlax-3d-point XAxis)          ;x-axis
                        (vlax-3d-point YAxis)          ;y-axis
                        NewUcsName
               )
  )
  (vla-put-origin objUCS (vlax-3d-point Origin))
  (if Activate
    (vla-put-activeucs kglobal:activedoc objUCS)
  )
  objUCS
)
;;
;;;-------------------------------------------------------------
;;;-------------------------------------------------------------
;;


« Last Edit: September 09, 2010, 06:36:19 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How would one create a null ObjectId?
« Reply #5 on: September 09, 2010, 07:19:06 AM »
@ highflybird
@ Kerry
I see that you both first create a ucs-object using 0,0,0 as the origin, and later change the origin to a new value. Why do you do that?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How would one create a null ObjectId?
« Reply #6 on: September 09, 2010, 08:50:43 AM »
I do it that way to try to reduce the effects of rounding errors.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How would one create a null ObjectId?
« Reply #7 on: September 09, 2010, 09:39:16 AM »
I do it that way to try to reduce the effects of rounding errors.
I may be wrong here, but it seems that using vla-add to create a new ucs-object doesn't require any calculations (apart from checking if UCSXDIR and UCSYDIR are a logical combination) . So I wouldn't expect any rounding errors...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How would one create a null ObjectId?
« Reply #8 on: September 09, 2010, 11:12:02 AM »
The way you guys show it is the way I'm doing it, except that I name it by a variable of date and time.  I'm thinking that I will create one just for the program, and if it's there, then just switch to that, and change it to be the previous UCS, as far as origin, x axis and y axis.

I was just hoping to not add items to the drawing that doesn't need to be there, so I was hoping there was a way that I can create a UCS only if needed, and then if I created it, I would delete it.  But that doesn't seem to be doable.

Thanks guys.

Edit: Added code for UCS I'm using

Code: [Select]
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq UcsName "OldUcsForCopyAlongCurve")
(setq UcsCol (vla-get-UserCoordinateSystems ActDoc))
(setq OldUcs
    (if (= (getvar 'UcsName) "")
        (if (not (vl-catch-all-error-p (setq OldUcs (vl-catch-all-apply 'vla-Item (list UcsCol UcsName)))))
            OldUcs
            (vlax-invoke UcsCol 'Add (getvar 'UcsOrg) (getvar 'UcsXDir) (getvar 'UcsYDir) UcsName)
        )
        (vla-get-ActiveUcs ActDoc)
    )
)
« Last Edit: September 09, 2010, 11:26:16 AM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How would one create a null ObjectId?
« Reply #9 on: September 09, 2010, 02:53:25 PM »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.