Author Topic: force network synch to update styles?  (Read 33411 times)

0 Members and 1 Guest are viewing this topic.

cadtag

  • Swamp Rat
  • Posts: 1152
force network synch to update styles?
« on: October 03, 2013, 08:57:08 PM »
If I change a structure in my stormwater drawing, and have already dref'ed that into a sheet - is there a way to force the synchronization to include the style from the master drawing?  Ex:  change a MH to a CB, or a CB to an MES in the master drawing, and the child drawing that has data-referenced in the pipe network is not updating the structure style to show the change.

Short of deleting and re-referencing (which would play hob with all the labels)
The only thing more dangerous to the liberty of a free people than big government is big business

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: force network synch to update styles?
« Reply #1 on: October 03, 2013, 10:08:52 PM »
Nope. You can manually change the style in the Dref drawing but nothing that's automatic.

cadtag

  • Swamp Rat
  • Posts: 1152
Re: force network synch to update styles?
« Reply #2 on: October 04, 2013, 11:03:59 AM »
ragnsnaggle grumble*@#%,  I thought DRefs were supposed to _save_ time and keep all the dependent drawings coordinated.

sounds like a job for SincPac -- or does no one ever do that kind of structure swap? 
The only thing more dangerous to the liberty of a free people than big government is big business

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: force network synch to update styles?
« Reply #3 on: October 04, 2013, 10:07:48 PM »
...... and keep all the dependent drawings coordinated.

sounds like a job for SincPac -- or does no one ever do that kind of structure swap? 
The issue stems from Autodesk thinks that it is a good idea to allow independent control of certain things in the dref'ed drawings so things can be shown differently. They semi-recently broke that philosophy, though, by changing how dref'ed pipe networks get synche'ed and apply the ObjectLayer settings. These now get reset to the drawing's settings every time a resync occurs. So no more placing existing pipes on a different layer, next time you open the drawing they will get moved back to the default layer.

So, IMHO, they should allow us to do what we want in the dref drawings, but should also allow us an easy way to update the structures & pipes if needed.

I will have a look at the API and see if this is something Sincpac might be able to address. Because yes, I have had occasion where I could've used this functionality.
« Last Edit: October 04, 2013, 10:17:35 PM by Jeff_M »

BlackBox

  • King Gator
  • Posts: 3770
Re: force network synch to update styles?
« Reply #4 on: October 05, 2013, 01:56:47 PM »
This has frustrated me since first working with Civil 3D.

It's unfortunate that there is not a Civil 3D-specific equivalent version to VISRETAIN (C3DVISRETAIN?), where this drawing-saved system variable would control the style of DREF Object(s).

... It would also be nice for LandXML to be enhaced to support parent AECC* Object(s) Style definitions... Meaning that if one were to import from LandXML, the assigned Styles were able to be brought in at import, rather than being a separate procedure either before, or after-the-fact.

Cheers
"How we think determines what we do, and what we do determines what we get."

cadtag

  • Swamp Rat
  • Posts: 1152
Re: force network synch to update styles?
« Reply #5 on: October 07, 2013, 08:45:03 AM »
LandXML, being a vendor agnostic data transfer format, really doesn't have a place for a program -specific concept like C3D styles.    One could always propose that at LandXML.org - dunno how open they are to suggestions though but might be worth trying.  I o htink it would be an improvement if the PointGroups in LandXML included the group definition, rather than _just_ the list of point numbers in the group.

CDSTYLERETAIN -  That would be a handy variable  - although VISRETAIN is pretty heavy-handed.  Personally I'd prefer something that could do a more selective 'refresh from source', be it layer properties or styles. 
The only thing more dangerous to the liberty of a free people than big government is big business

BlackBox

  • King Gator
  • Posts: 3770
Re: force network synch to update styles?
« Reply #6 on: October 07, 2013, 09:28:00 AM »
LandXML, being a vendor agnostic data transfer format, really doesn't have a place for a program -specific concept like C3D styles.    One could always propose that at LandXML.org - dunno how open they are to suggestions though but might be worth trying.  I o htink it would be an improvement if the PointGroups in LandXML included the group definition, rather than _just_ the list of point numbers in the group.

I didn't think about that... Perhaps a secondary file export (when LandXML export is done from C3D) of same LandXML file name, and different file extension (maintaining XML schema, like .APC?), which if found during LandXML import C3D would perform the style import?

Personally I'd prefer something that could do a more selective 'refresh from source', be it layer properties or styles.

I've never inspected what information is available from a given data reference before, but assuming that one can identify the parent drawing....

@Jeff - That could be incorporated easy enough via a ContextMenuExtension for the appropriate RXClass, no?



I usually use LISP to restore an XREF's layer properties via ObjectDBX in VISRETAIN == 1... I could easily see developing this for the AutoCAD side of things in .NET API, as I seem to be coding a lot of ContextMenuExtensions these days. Performing this via .NET side Database in lieu of ObjectDBX *should* be faster as well.

Cheers
"How we think determines what we do, and what we do determines what we get."

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: force network synch to update styles?
« Reply #7 on: October 07, 2013, 10:19:21 AM »

@Jeff - That could be incorporated easy enough via a ContextMenuExtension for the appropriate RXClass, no?

Yes, I'm sure it could be. However, in my initial inspection I have found no method for obtaining the source drawing info from a Dref'ed object. I posted a question about this on the C3D customization forum. We'll see what Partha has to say.

BlackBox

  • King Gator
  • Posts: 3770
Re: force network synch to update styles?
« Reply #8 on: October 07, 2013, 10:51:27 AM »

@Jeff - That could be incorporated easy enough via a ContextMenuExtension for the appropriate RXClass, no?

Yes, I'm sure it could be. However, in my initial inspection I have found no method for obtaining the source drawing info from a Dref'ed object. I posted a question about this on the C3D customization forum. We'll see what Partha has to say.

The parent drawing is specified within the respective DREF's XML 'shortcut'... Example from an Alignment (reformatted for clarity):

Code - XML: [Select]
  1. <?xml version="1.0"?>
  2. <!--PLEASE DO NOT EDIT THIS FILE!-->
  3. <ProjectInfo>
  4.         <ProjectDesc>
  5.         </ProjectDesc>
  6.         <Shortcuts>
  7.                 <Shortcut name="<FILEPATH>\<FILENAME>.dwg:<DREF NAME HERE>">
  8.                         <DwgRelPath path=".\<RELATIVEPATH>\<FILENAME>.dwg"/>
  9.                         <Criteria>
  10.                                 <File name="<FILEPATH>\<FILENAME>.dwg"/>
  11.                                 <Object
  12.                                         type="AeccDbAlignment"
  13.                                         useType="-1"
  14.                                         name="<DREF NAME HERE>"
  15.                                         useName="-1"
  16.                                         version="0"
  17.                                         useVersion="0"
  18.                                         handleLow="2786"
  19.                                         handleHigh="0"
  20.                                         useHandle="-1"
  21.                                         parentHandleHigh="0"
  22.                                         parentHandleLow="0"/>
  23.                                 <DisplayProperties
  24.                                         layer="0"
  25.                                         useLayer="0"
  26.                                         color="3"
  27.                                         useColor="0"
  28.                                         lineType="ByLayer"
  29.                                         useLineType="0"
  30.                                         lineWeight="-1"
  31.                                         useLineWeight="0"
  32.                                         <!--THIS IS WHERE C3D STYLE DEFINITION SHOULD BE SPECIFIED, AND IMPORTED FROM?-->
  33.                                         />
  34.                         </Criteria>
  35.                 </Shortcut>
  36.         </Shortcuts>
  37. </ProjectInfo>
  38.  



The problem being that each 'shortcut' XML file name includes its own GUID actually in the file name itself. One could simply iterate the ..\_Shortcuts\ folder looking for an XML File.Name.Contains(<DrefObjectName>), but I'd hope that Partha can identify a more direct means of accessing this aspect of the C3D API.

Cheers
"How we think determines what we do, and what we do determines what we get."

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: force network synch to update styles?
« Reply #9 on: October 07, 2013, 12:03:29 PM »
....but I'd hope that Partha can identify a more direct means of accessing this aspect of the C3D API.

Cheers
Especially since the shortcut folder can be removed and, as long as the pathing remains the same, the Drefs will still work. The only time the XML file is needed is when creating the Dref or when the source object cannot be located. Furthermore, I can add a reference from 2 different shortcut paths into one drawing...not that this is a common occurrence, but it can, and does, get utilized. So now how do you know which Shortcuts folder to access?

BlackBox

  • King Gator
  • Posts: 3770
Re: force network synch to update styles?
« Reply #10 on: October 07, 2013, 12:31:35 PM »
Especially since the shortcut folder can be removed and, as long as the pathing remains the same, the Drefs will still work. The only time the XML file is needed is when creating the Dref or when the source object cannot be located.

I only mentioned it as a possible (albeit imperfect) workaround, but am still hopeful for some sort of P/Invoke Method for being able to access the appropriate string directly.

Much the same as one can programmatically modify ..\ShortcutFolders.xml : /WorkingFolders/WorkingFolder XmlNodes' Current XmlAttribute, followed by a call to RefreshShortcutNode Command in order to change the working folder on the fly... Granted this example is not directly related, but is just an example of how one might utilize such a workaround (hack?) with the external XML if no direct API access exists.

... Now if only I could find a way of adding a ContextMenuExtension to the native Toolspace 'Data Shortcuts' node, or Layer Manager's Layer Items (for the pseudo-named 'Xref Layer Restore...' mentioned earlier, rather than attaching for RXClass == BlockReference, and being relegated to filtering for ObjectId.ObjectClass.Name == "AcDbBlockReference" & then BlockTableRecord.XrefStatus == XrefStatus.Resolved, etc.)

/OffTopic



Furthermore, I can add a reference from 2 different shortcut paths into one drawing...not that this is a common occurrence, but it can, and does, get utilized. So now how do you know which Shortcuts folder to access?

Interesting... Given the relative simplicity of our projects, I've never tried such a task, but I would presume that C3D precludes one from creating two DREFs of the same name, regardless of where the shortcut definition (XML) resides, no?

Cheers
"How we think determines what we do, and what we do determines what we get."

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: force network synch to update styles?
« Reply #11 on: February 27, 2015, 12:48:22 AM »
After much hair pulling, I decided to try and create a way to update dref pipe networks to match style and object layer of the parent pipe network. I couldn't figure out how to find the file where dref is targeting, so I just manually select the source file. Using ODBX, I can extract structure & pipe styles and layer (atm, it only deals with structures - testing simplicity), but when it iterates through the active drawing, where the dref network resides, it finds a matching part, but cannot apply a different style to the structure. I get nothing but "Error: Member not found".

I am curious, Jeff, if you made any progress with something of the sort.

I have a feeling legacy COM just has a bug that won't allow the user to change the structure style. I even made a simple command to do nothing but collect a list of structure styles in the active drawing and apply one of them to a selected structure.

I've attached all my code, for anyone that may be interested; the "test" command is my failed sync attempt and the "css" command is my testing function to choose a style from a list and apply it to a single selected structure (no error checking).

Code: [Select]
(defun c:test (/ *error* ss i objlst stylelst file odbx parts ass a b c)

  (defun *error* (msg)
    (and odbx (vlax-release-object odbx))
    (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
      (progn (vl-bt) (princ (strcat "\nError: " msg)))
    )
  )



  (cond

    ;; check if a pipe network exists in drawing and is a reference
    ((progn
       (if (setq ss (ssget "_X" '((0 . "AECC_STRUCTURE"))))
(repeat (setq i (sslength ss))
   (setq o (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
   (if (eq (vlax-invoke o 'IsReferenceObject) 1) ; is dref part?
     (setq objlst (cons (cons (strcat (vla-get-name o) "_" (vlax-get o 'PartSizeName)) o)
objlst
  )
     )
   )
)
       )
       (not objlst)
     )
     (alert "No Data Referenced parts in active drawing.")
    )

    ;; get list of structure styles in active drawing
    ((progn
       (vlax-for x (vlax-get (AT:PipeDoc) 'StructureStyles)
(setq stylelst (cons (cons (vla-get-name x) x) stylelst))
       )
       (not stylelst)
     )
     (alert "No Part Styles in active drawing.")
    )

    ;; located master network dwg to sync files
    ((not (setq file (getfiled "Select drawing where master pipe network resides"
       (getvar 'DWGPREFIX)
       "dwg"
       2
     )
  )
     )
    )

    ;; odbx master file
    ((not
       (if (setq odbx (vlax-create-object
(if (< (setq release (atoi (getvar 'ACADVER))) 16)
  "ObjectDBX.AxDbDocument"
  (strcat "ObjectDBX.AxDbDocument." (itoa release))
)
      )
   )
(progn (vla-open odbx file) t)
       )
     )
     (alert "File could not be opened.")
    )

    ;; step through odbx drawing, find networks, extract style name
    ((progn
       (vlax-for x (vla-get-block (vla-get-layout (vla-get-modelspace odbx)))
(if (member (vla-get-objectname x) '("AeccDbStructure"))
   (setq parts (cons (cons (strcat (vla-get-name x) "_" (vlax-get x 'PartSizeName))
   (list (vla-get-name (vlax-get x 'Style))
(vla-get-layer x)
   )
     )
     parts
       )
   )
)
       )

       ;; (startapp "notepad" (AT:WriteToFile (vl-filename-mktemp nil nil "txt") parts t))

       (not parts)
     )
     (alert "No pipe networks in selected drawing.")
    )

    (t
     (foreach x objlst
       (if (setq ass (cdr (assoc (car x) parts)))
(progn
;;;    (setq a (cdr x)
;;; b (car ass)
;;; c (cdr (assoc (car ass) stylelst))
;;;    )
;;;    (startapp "notepad" (AT:WriteToFile (vl-filename-mktemp nil nil "txt") (list a b c) t))

   (vl-catch-all-apply 'vlax-put (list (cdr x) 'Style (cdr (assoc (car ass) stylelst))))
   (vl-catch-all-apply 'vla-put-layer (list (cdr x) (cadr ass)))
)
       )
     )
    )



  )

  (*error* nil)

  (princ)
)






(defun c:css (/ o stylelst style)

  (vlax-for x (vlax-get (AT:PipeDoc) 'StructureStyles)
    (setq stylelst (cons (cons (vla-get-name x) x) stylelst))
  )

  (if (and (setq o (car (entsel "\nSelect c3d structure: ")))
   (setq style (car (at:listselect "" "" 15 15 "false" (mapcar 'car stylelst))))
      )
    (vlax-put (vlax-ename->vla-object o) 'style (cdr (assoc style stylelst)))
  )

  (princ)
)



(defun AT:WriteToFile (file lst overwrite / fo)
  ;; Write list to file
  ;; file - file to write list to (must be in form "c:\\File.txt")
  ;; lst - list to write to file
  ;; overwrite - If T, will overwrite; nil to append
  ;; Alan J. Thompson, 04.28.09
  (if (and (vl-consp lst)
   (setq fo (open file
  (if overwrite
    "W"
    "A"
  )
    )
   )
      )
    (progn (foreach x lst (write-line (vl-princ-to-string x) fo))
   (close fo)
   file
    )
  )
)



(defun AT:ListSelect (title label height width multi lst / fn fo d item f)
  ;; List Select Dialog (Temp DCL list box selection, based on provided list)
  ;; title - list box title
  ;; label - label for list box
  ;; height - height of box
  ;; width - width of box
  ;; multi - selection method ["true": multiple, "false": single]
  ;; lst - list of strings to place in list box
  ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
  (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
   (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
   (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
   (strcat "width = " (vl-princ-to-string width) ";")
   (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
     )
    (write-line x fo)
  )
  (close fo)
  (new_dialog "list_select" (setq d (load_dialog fn)))
  (start_list "lst")
  (mapcar (function add_list) lst)
  (end_list)
  (setq item (set_tile "lst" "0"))
  (action_tile "lst" "(setq item $value)")
  (setq f (start_dialog))
  (unload_dialog d)
  (vl-file-delete fn)
  (if (= f 1)
    ((lambda (s / i s l)
       (while (setq i (vl-string-search " " s))
(setq l (cons (nth (atoi (substr s 1 i)) lst) l))
(setq s (substr s (+ 2 i)))
       )
       (reverse (cons (nth (atoi s) lst) l))
     )
      item
    )
  )
)


;   IsReferenceObject ()
;   IsReferenceStale ()
;   IsReferenceSubObject ()
;   IsReferenceValid


;;;  (vlax-for x (vla-get-block
;;;                  (vla-get-layout (vla-get-modelspace oDoc))
;;;                )



(defun AT:AeccDoc (/ i c)
  ;; Return and set (as global variable *AeccDoc*) Civil 3D Aecc Document object
  ;; (will also set global variables for acad object *Acad* and c3d aecc application *AeccApp*)
  ;; Alan J. Thompson, 2013.11.27, 2014.03.20
  (cond (*AeccDoc*)
((progn
   (setq i 2.9)
   (while (and (<= (setq i (+ i 0.1)) 50.) (not *AeccApp*))
     (if (not (vl-catch-all-error-p
(setq c (vl-catch-all-apply
  'vla-getinterfaceobject
  (list (cond (*Acad*)
      ((setq *Acad* (vlax-get-acad-object)))
)
(strcat "AeccXUiLand.AeccApplication." (vl-princ-to-string i))
  )
)
)
      )
)
       (setq *AeccApp* c)
     )
   )
   *AeccApp*
)
(setq *AeccDoc* (vlax-get *AeccApp* 'ActiveDocument))
)
  )
)


(defun AT:PipeDoc (/ i c)
  ;; Return and set (as global variable *PipeDoc*) Civil 3D Pipe Document object
  ;; (will also set global variables for acad object *Acad* and c3d pipe application *AeccApp*)
  ;; Alan J. Thompson, 2015.02.26
  (cond
    (*PipeDoc*)
    ((progn
       (setq i 2.9)
       (while (and (<= (setq i (+ i 0.1)) 50.) (not *PipeApp*))
(if (not (vl-catch-all-error-p
    (setq c (vl-catch-all-apply
      'vla-getinterfaceobject
      (list (cond (*Acad*)
  ((setq *Acad* (vlax-get-acad-object)))
    )
    (strcat "AeccXUiPipe.AeccPipeApplication." (vl-princ-to-string i))
      )
    )
    )
  )
     )
   (setq *PipeApp* c)
)
       )
       *PipeApp*
     )
     (setq *PipeDoc* (vlax-get *PipeApp* 'ActiveDocument))
    )
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: force network synch to update styles?
« Reply #12 on: February 27, 2015, 09:47:52 AM »
Alan, not sure why the structure style cannot be set. I've tried a few different things with no success. BTW, I was getting an "unwind skipped on exception" error using your AT:PipeDoc function (I only tested the CSS command). I edited to be a bit more direct and then it allowed me to see it fail at the setting of the style:
Code - Auto/Visual Lisp: [Select]
  1. (defun AT:PipeDoc (/ i c C3D)
  2.   ;; Return and set (as global variable *PipeDoc*) Civil 3D Pipe Document object
  3.   ;; (will also set global variables for acad object *Acad* and c3d pipe application *PipeApp*)
  4.   ;; Alan J. Thompson, 2015.02.26
  5.   (cond
  6.     (*PipeDoc*)
  7.     ((and (setq *Acad* (vlax-get-acad-object))
  8.        (setq C3D (strcat "HKEY_LOCAL_MACHINE\\" (if vlax-user-product-key (vlax-user-product-key) (vlax-product-key) ) )
  9.       C3D (vl-registry-read C3D "Release")
  10.       C3D (substr C3D 1 (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1) ) )
  11.       *PipeApp* (vla-getinterfaceobject *Acad* (strcat "AeccXUiPipe.AeccPipeApplication." C3D) )
  12.       )
  13.   )
  14.      (setq *PipeDoc* (vlax-get *PipeApp* 'ActiveDocument))
  15.     )
  16.   )
  17. )
  18.  

BlackBox

  • King Gator
  • Posts: 3770
Re: force network synch to update styles?
« Reply #13 on: February 27, 2015, 11:05:10 AM »
I couldn't figure out how to find the file where dref is targeting, so I just manually select the source file.

Quite a bit more difficult with LISP than with .NET, but the files you're after are the same.

<RoamableRootPrefix> + "Project Management\\ShortcutFolders.xml will provide the WorkingFolder/ShortcutFolder XmlNode's path XmlAttribute's string value, which then allows you to locate <ShortcutFolderPathValue> + "\\_shortcuts\\<YourC3dObjectType>\\" in order to iterate the XML files contained within, and WCMATCH the XML file with the "<C3DObjectName>_<GUID>.xml" file naming convention.

At this point, you open the "<C3DObjectName>_<GUID>.xml" file, and obtain ProjectInfo/Shortcuts/Shortcut/DwgRelPath XmlNode's path XmlAttribute's value, or ProjectInfo/Shortcuts/Shortcut/Criteria/File XmlNode's name XmlAttribute's value for full file path.

HTH
"How we think determines what we do, and what we do determines what we get."

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: force network synch to update styles?
« Reply #14 on: February 27, 2015, 05:35:27 PM »
Alan, not sure why the structure style cannot be set. I've tried a few different things with no success. BTW, I was getting an "unwind skipped on exception" error using your AT:PipeDoc function (I only tested the CSS command). I edited to be a bit more direct and then it allowed me to see it fail at the setting of the style:
Code - Auto/Visual Lisp: [Select]
  1. (defun AT:PipeDoc (/ i c C3D).....
  2.  
Crap. I was hoping I was doing something wrong, or it was just my version of c3d. Thank you for a better way to retrieve the version info; that's pretty damn slick.

I couldn't figure out how to find the file where dref is targeting, so I just manually select the source file.

Quite a bit more difficult with LISP than with .NET, but the files you're after are the same.

<RoamableRootPrefix> + "Project Management\\ShortcutFolders.xml will provide the WorkingFolder/ShortcutFolder XmlNode's path XmlAttribute's string value, which then allows you to locate <ShortcutFolderPathValue> + "\\_shortcuts\\<YourC3dObjectType>\\" in order to iterate the XML files contained within, and WCMATCH the XML file with the "<C3DObjectName>_<GUID>.xml" file naming convention.

At this point, you open the "<C3DObjectName>_<GUID>.xml" file, and obtain ProjectInfo/Shortcuts/Shortcut/DwgRelPath XmlNode's path XmlAttribute's value, or ProjectInfo/Shortcuts/Shortcut/Criteria/File XmlNode's name XmlAttribute's value for full file path.

HTH
Pretty slick. I didn't realize that info was stored anywhere. Of course, without the ability to set the style, I've hit a brick wall. I've put learning to code in .net off for too long because I was "busy" or just being lazy, and now it's a real issue.
Can the structure/pipe style be successfully set in the .net api?
Time to start studying.
Thanks, guys.  :|
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox