Author Topic: ucs importing (i'll be nice if you are....)  (Read 2571 times)

0 Members and 1 Guest are viewing this topic.

gatorcadd

  • Guest
ucs importing (i'll be nice if you are....)
« on: February 22, 2008, 06:29:08 PM »
is there a way to import the named ucs settings from one file to another?  i have one file for dimensions and layout that i set the ucs to different angles (to match the streets)

i want to import the same ones into a landscape drawing so i can match the viewports.

the design center doesn't allow for this as a subject to pick from so if anyone knows another way to do it, please feel free to throw it out there.

i was thinking of using the design center to import the layouts, but i don't think that would work...
i promise to wait patiently... (this time) :-(

Josh Nieman

  • Guest
Re: ucs importing (i'll be nice if you are....)
« Reply #1 on: February 22, 2008, 06:34:44 PM »
ooh... good question.  I know of no way to do so, but I have a tip for working around this.

Go to the source drawing with the named UCS... draw a line along the XY plane at 0degrees from X.  Then draw a line on the YZ plane 0d from Y.  Do the same... basically make lines that define the axes.

Set the UCS to World, in your source drawing.
Go to destination drawing, with UCS set to World, paste the lines, and then create a new UCS using those lines as guides for selecting the directions.

Sorry I can't think of a more automated and easier way, but if you hadn't already figured that part out, at least that'll gitcha by.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ucs importing (i'll be nice if you are....)
« Reply #2 on: February 22, 2008, 06:53:04 PM »
You can do it with lisp and objectdbx.

Core command, I don't know of any.  If you insert the drawing with the ucs's they wouldn't copy over, so I'm not sure how else to do it.
Tim

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

Please think about donating if this post helped you.

gatorcadd

  • Guest
Re: ucs importing (i'll be nice if you are....)
« Reply #3 on: February 22, 2008, 08:27:18 PM »
the first one is what i expected i had to do.  i don't lisp, or vba or anything short of creating macros.  but i never thought about inserting the drawing into the new drawing.  i will try that.

nope didn't work.

you would think that they would have picked that one up...

i guess i will do what josh suggested.  i just wish it was quicker.  i only have five to do...


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ucs importing (i'll be nice if you are....)
« Reply #4 on: February 22, 2008, 09:01:04 PM »
Have a play with this scooter ...

Code: [Select]
// CodeHimBelongaKwb ©  Feb 2008

;; import named user coordinate systems from selected source file
(defun c:importucssystem (/                iacaducss
                          sourcedocumentpath
                          sourcedocumentdbx
                          sourceiacaducss  cnt
                          ucsname          ucslist
                         )
  (setq iacaducss (vla-get-usercoordinatesystems
                    (vla-get-activedocument
                      (vlax-get-acad-object)
                    )
                  )
  )
  (and (setq
         sourcedocumentpath (getfiled "Source File"
                                      (getvar "dwgprefix")
                                      "dwg"
                                      0
                            )
       )
       (setq sourcedocumentdbx
              (dbxdocumentatpath sourcedocumentpath
              )
       )
       (setq sourceiacaducss (vla-get-usercoordinatesystems
                               sourcedocumentdbx
                             )
       )
       (< 0 (vlax-get sourceiacaducss 'count))
       (setq cnt 0)
       (vlax-for ucsobject sourceiacaducss
         (setq ucsname (vlax-get ucsobject 'name))
         (if (and (not (tblsearch "ucs" ucsname))
                  (not (wcmatch ucsname "_Active*"))
             )
           (setq ucslist (cons ucsobject ucslist)
                 cnt     (1+ cnt)
           )
         )
       )
       (not (vlax-invoke sourcedocumentdbx
                         'copyobjects
                         ucslist
                         iacaducss
            )
       )
       (princ (strcat "\n "
                      (itoa cnt)
                      " coordinate systems were imported."
              )
       )
  )
  (if sourcedocumentdbx
    (vlax-release-object sourcedocumentdbx)
  )
  (princ)
)



;; return an open document or ODBX doc
;; argument: full path
(defun dbxdocumentatpath  (path / *acad* documents sourcedocumentdbx)
  (setq *acad*    (vlax-get-acad-object)
        documents (vla-get-documents *acad*)
  )
  ;;check the documents collection
  (vlax-for item documents
    (if (= path (vlax-get item 'fullname))
      (setq sourcedocumentdbx item)
    )
  )
  ;;if not in documents collection, use ObjectDBX
  (if (null sourcedocumentdbx)
    (cond ((> (atoi (getvar "AcadVer")) 15)
           (setq
             sourcedocumentdbx (if (< (setq
                                        vers (substr
                                               (getvar "acadver")
                                               1
                                               2
                                             )
                                      )
                                      "16"
                                   )
                                 (vla-getinterfaceobject
                                   (vlax-get-acad-object)
                                   "ObjectDBX.AxDbDocument"
                                 )
                                 (vla-getinterfaceobject
                                   (vlax-get-acad-object)
                                   (strcat
                                     "ObjectDBX.AxDbDocument."
                                     vers
                                   )
                                 )
                               )
           )
           (vla-open sourcedocumentdbx path)
          )
          (t (alert "too bad, so sad"))
    )
  )
  sourcedocumentdbx
)
« Last Edit: February 22, 2008, 09:04:15 PM by Kerry Brown »
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.

gatorcadd

  • Guest
Re: ucs importing (i'll be nice if you are....)
« Reply #5 on: February 22, 2008, 09:28:24 PM »
as always you are the bomb... :lol:

that worked sweeeeettttt!!!!

you should sell that one, or at least throw it at the guru's  :lmao: at autodesk....
« Last Edit: February 22, 2008, 10:15:28 PM by gatorcadd »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ucs importing (i'll be nice if you are....)
« Reply #6 on: February 22, 2008, 09:46:17 PM »
Quote from: Scooter

..........

You should sell that one, ..............


You offering to be a client ??  :?
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.

gatorcadd

  • Guest
Re: ucs importing (i'll be nice if you are....)
« Reply #7 on: February 22, 2008, 09:51:55 PM »
maybe...

do you type all of that yourself, or do you use a lisp generator?

it seems like you did it quite quickly...you must be very fast.

not in the market for purchasing anything today, but i will keep you in mind for the bigger ones...
i have a few i might throw at you if i cant be more productive the way i expect.  there are some that i have that dont work the way i want and i might throw them at you to see if you can fix them...

« Last Edit: February 22, 2008, 10:15:41 PM by gatorcadd »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ucs importing (i'll be nice if you are....)
« Reply #8 on: February 22, 2008, 09:58:50 PM »

maybe...

do you type all of that yourself, or do you use a lisp generator?

.............

a lisp generator ??  and You promised to be nice .. Hah !
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ucs importing (i'll be nice if you are....)
« Reply #9 on: February 25, 2008, 11:20:54 AM »
A different approach that is more a tool for coders than end users --

Code: [Select]
(defun _CopyTable ( sourceDoc targetDoc table pattern / @GetName collection array result )

[color=green]    ;;  Source and target docs can be opened in the editor
    ;;  or via ObjectDBX, no matter.
    ;;
    ;;  Table needs to a symbol corresponding to a valid
    ;;  table that is a direct child of an AutoCAD document,
    ;;  for example, 'Block, 'Dictionaries, 'Dimstyles etc.
    ;;
    ;;  Pattern is used to limit the copy to specific item
    ;;  names (if so desired). If not a strng, ie null it's
    ;;  coerced to "*"; everything.
    ;;
    ;;  eg: (_CopyTable doc1 doc2 'UserCoordinateSystems "*")[/color]
   
    (defun @GetName ( item / result )
   
[color=green]        ;;  some collection items don't have names,
        ;;  for example some dictionary entries, so
        ;;  let's trap that potential error[/color]
   
        (if
            (vl-catch-all-error-p
                (vl-catch-all-apply
                   '(lambda ( )
                        (setq result (vla-get-name item))
                    )
                )
            )
            ""
            result
        )                             
   
    )
   
[color=green]    ;;  ok, let's roll ...   [/color]
   
    (setq
        collection (vlax-get-property targetDoc table)
        pattern    (if (eq 'str (type pattern)) (strcase pattern) "*")
        array      (vlax-make-safearray vlax-vbObject '(0 . 0))       
    )
   
[color=green]    ;;  The following looks inefficient but it thwarts a
    ;;  complete copy failure if one item makes chucks a
    ;;  wobbly, which is what would happen if you put all
    ;;  the candidate objects in one safe array and then
    ;;  invoked the CopyObjects method on the entire lot.
    ;;  The preceding theory is actually a guess and not
    ;;  proven as of yet, but that's the rationale for
    ;;  coding it this way. When I've some time I'll
    ;;  determine if any collections make the CopyObjects
    ;;  function toss its cookies if copied en masse. If
    ;;  not I'll revise to reflect.[/color]
   
    (vlax-for item (vlax-get sourceDoc table)
        (if (wcmatch (strcase (@GetName item)) pattern)
            (vl-catch-all-apply
               '(lambda ( )
                    (vlax-invoke-method
                        sourceDoc
                       'CopyObjects
                        (progn
[color=green]                            ;;  slightly faster than vlax-safearray-fill[/color]
                            (vlax-safearray-put-element array 0 item)
                            array
                        )   
                        collection
                    )
                    (setq result (cons item result))
                )
            )               
        )   
    )
   
[color=green]    ;;  let the caller know what we successfully copied[/color]
   
    (reverse result)
   
)

Example:

Code: [Select]
[color=green];;  assumes dbx1 and dbx2 are valid document objects[/color]

(if (setq copied (_CopyTable dbx1 dbx2 'UserCoordinateSystems "test*"))
    (progn
        (princ "Copied these UCSs:\n")
        (mapcar
           '(lambda (item) (print (vla-get-name item)))
            copied
        )
        (princ)
    )       
)
   

Might spit this back:

Copied these UCSs:

"Test1"
"Test2"
"Test3"




For what it's worth ... Michael.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ucs importing (i'll be nice if you are....)
« Reply #10 on: February 25, 2008, 11:41:19 AM »
If it turns out the cautious approach is overkill here's the en masse version.

Code: [Select]
(defun _CopyTable ( sourceDoc targetDoc table pattern / @GetName collection result )

[color=green]    ;;  Source and target docs can be opened in the editor
    ;;  or via ObjectDBX, no matter.
    ;;
    ;;  Table needs to a symbol corresponding to a valid
    ;;  table that is a direct child of an AutoCAD document,
    ;;  for example, 'Block, 'Dictionaries, 'Dimstyles etc.
    ;;
    ;;  Pattern is used to limit the copy to specific item
    ;;  names (if so desired). If not a strng, ie null it's
    ;;  coerced to "*"; everything.
    ;;
    ;;  eg: (_CopyTable doc1 doc2 'UserCoordinateSystems "*")[/color]

    (defun @GetName ( item / result )

[color=green]        ;;  some collection items don't have names,
        ;;  for example some dictionary entries, so
        ;;  let's trap that potential error[/color]

        (if
            (vl-catch-all-error-p
                (vl-catch-all-apply
                   '(lambda ( )
                        (setq result (vla-get-name item))
                    )
                )
            )
            ""
            result
        )

    )

[color=green]    ;;  ok, let's roll ...[/color]

    (setq
        collection (vlax-get-property targetDoc table)
        pattern    (if (eq 'str (type pattern)) (strcase pattern) "*")
    )

[color=green]    ;;  find the items that match out pattern[/color]

    (vlax-for item (vlax-get sourceDoc table)
        (if (wcmatch (strcase (@GetName item)) pattern)
            (setq items (cons item items))
        )
    )
   
[color=green]    ;;  'Kay, we got stuff, copy it to the target doc[/color]

    (if items
        (setq result
            (if
                (vl-catch-all-error-p
                    (vl-catch-all-apply
                       '(lambda ( )
                            (vlax-invoke-method
                                sourceDoc
                               'CopyObjects
                                (vlax-safearray-fill
                                    (vlax-make-safearray
                                        vlax-vbObject
                                        (cons 0 (1- (length items)))
                                    )
                                    items
                                )
                                collection
                            )
                        )
                    )
                )
               
                nil
               
                items
               
            )
        )     
    )

[color=green]    ;;  let the caller know what we successfully copied[/color]

    (reverse result)

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Guest

  • Guest
Re: ucs importing (i'll be nice if you are....)
« Reply #11 on: February 25, 2008, 11:54:24 AM »
Seems I'm a bit late to the party.... Here's a VBA version with a dialog box that allows you to pick and choose which UCS to import.