Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy/Import Civil3D settings (styles) between drawings

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
norman.yuan
2489 Views, 6 Replies

Copy/Import Civil3D settings (styles) between drawings

Is there a way to copy/import Civil3D settings (various styles for points, labels...) from one drawing to another? 

 

Background: I am building a Civil3D app that requires particular point styles and label styles preexist in the drawing. We all know how complicated to set up styles in Civil3D. When it comes to an app that may be used in a huge company with offices in different countries/regions, the drawings this app applies to may be based on different Civil3D drawing templates, thus, the required Civil3D settings (styles) may not be there. Since I do know the required Styles are stored in a given drawing template, so, I am thinking when the app starts, it would check if the required styles exist in the working drawing. If not, imported them from that given template. Sounds reasonable?

 

If the data to be copied/imported in plain AutoCAD, it would be simple: Database.DeepCloneObjects()/Database.WblockCloneObjects() does the work. However, it seems there is not way to use these methods with Civil3D objects, when the objects are styles: because these 2 methods need to supply a Owner ID, which is not available in the Civil3D object, such as Style. Behind scene, I could guess the owner(s) would be undocumented NamedDictionaries, but Civil#D API certainly does not expose it.

 

So, is it possible to copy/import Civil3D settings, such as styles, programmatically?

Norman Yuan

Drive CAD With Code

EESignature

6 REPLIES 6
Message 2 of 7
norman.yuan
in reply to: norman.yuan

Well, as many people often do, once the question is posted, a solution comes in front of you. I guess, spend a time typing a question would calm down the struggling mind Smiley Sad

 

In my case, StyleBase.ExportTo() method just does what I needed.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 7
LASSAADTH
in reply to: norman.yuan

You can also use the basic command "IMPORTSTYLESAND SETTINGS" It works perfectly.

Lassaad THALJAOUI
Infrastructure Engineer
Autodesk Product professional User
Civil 3D 2016 x64 / Windows 7 64-bit / 16GB RAM
Message 4 of 7
Buzz0m
in reply to: norman.yuan

Hi,

I'm curious to how you managed to do this. I am under the impression that you, @norman.yuan, created something bigger than just one "command" but nevertheless I would like to know:

  1. Were you able to import the styles to an active and opened dwg-file with the stylebase.ExportTo()-method or does this work only with files that are not open for edit?
  2. Are you aware of any other ways of doing this with lighter solutions than compiled .dll files and netloading them?
    1. I'm thinking of lisp and something like:
      (command "-importstylesandsettings" "[filePath]" ...)

 

Message 5 of 7
norman.yuan
in reply to: Buzz0m

@Buzz0m ,

 

As my original post showed, I was asking a programmatical solution (I was doing C3D .NET API coding). So, yes, the StyleBase.ExportTo() does what I wanted in such a situation:

 

1. With an active drawing open in C3D;

2. My running .NET code examine the active drawing to see whether particular styles exist or not, for this particular drawing (according to its project type, or project region, client, or whatever ...);

3. If required style(s0 missing, the code would open corresponding template drawing as a side C3D document (i.e. opens it in C3D app's memory, but not visually in AutoCAD editor);

4. Call StyleBase.ExportTo() from the side C3D document to export selected styles into the active drawing;

5. After the exporting (importing, for the active drawing) is done, close the side C3D document.

 

I think the "IMPORTSTYLESANDSETTINGS" uses the same API call (on ObjectARX level). The problem of using LISP to call this command is that if you only need import particular styles/settings, you need to search the source/template drawing for the IDs of those styles/settings, thus you need the source/template drawing being opened in AutoCAD editor, unless you want import everything. I never tried it with this command in command line mode (prefix it with "-"), and not sure after supplying file name, if the dialog box would still pops up. If so, lisp execution is interrupted and become manual command execution. While with .NET API app, the code runs all behind the scene and user does not see/feel another drawing is opened for retrieving data from, except for a few seconds of wait. Of course as programmer, I can easily mimic the IMPORTSTYLESANDSETTINGS command, and replace the dialog box for choosing styles/settings to be imported with a simplified UI, or make the user interaction 100% command line, such as telling user which style/setting is missing, pressing "yes/no" to import. Then, if required, my custom importing process code can be exposed as LISP function, so that it appears like a "lighter" solution with much less or no user interaction needed.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 7
Buzz0m
in reply to: norman.yuan

Thank you for the elaboration! I believe the lisp approach fails exactly on the fact that the lisp is interrupted. The only logical path seems to be the one you described.

 

My case is to import and overwrite all styles from a "template" drawing via toolpalette button. But I'll have to develop some better coding skills before I get this task done but you have given me a good direction! Thank you!

Message 7 of 7

Is there any risk of damaging a file if you use the importdrawingsettings command to bring styles and settings from your most recent project to your next project? My coworker will take line work from a layout done in a regular AutoCAD file, and use the command to pull everything from his last project. He's done over 20 projects in a row pulling from the previous. Will doing that over and over again eventually corrupt a file or cause some other problem? When I took an intro Civil 3D class two years ago the instructor said to always paste that line work into a Civil 3D template. Can't remember if he mentioned styles and settings command or if it would do harm. I do remember him saying that your Civil 3D layers, objects and settings are already in the template and are not in the AutoCAD file.

 

My coworker has more experience designing than me, but is self taught at using Civil 3D. He disagrees with me that he should paste the line work into the template. His only reasoning is that importstylesandsettings has worked the last 20 times. My reasoning is that my very experienced instructor said to use a template. Will this lead to any problems on future projects?

 

My instructor told me a few general things that could corrupt a file like opening a file through Windows Explorer rather than opening it through the Civil 3D program. That was something I never considered would ruin a file, so I want to be cautious of going against what my instructor said. Thank you!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report