Results 1 to 9 of 9

Thread: Batch Converting CTB to STB

  1. #1
    Member
    Join Date
    2008-06
    Posts
    11
    Login to Give a bone
    0

    Default Batch Converting CTB to STB

    Here's my question:

    Is there another mechanism than "SendStringToExecute" or the Interop SendCommand() for sending a command such as convertpstyles to AutoCAD and getting .NET to wait for it to finish before proceeding?

    I've got CommandEnded code that handles waiting for MTEXT and DTEXT commands to finish and I've tried constructing a CommandEnded for CONVERTPSTYLES, but it seems to me that commands that throw dialogue boxes such as CONVERTPSTYLES aren't handled the same way.

    I've tried setting FILEDIA to 0 prior to running the CONVERTPSTYLES command, however the message box that CONVERTPSTYLES presents before asking for the STB file appears to be getting in the way.

    Any suggestions would be greatly appreciated.

    --------------------------------------------------------------------------------------------------------------
    And here's some background:

    As an organisation, we have opted to go with STB as we have some complicated requirements that CTB doesn't accommodate. The wisdom of that decision is a moot point and I'm aware of the vast array of opinion.

    We have a legacy of CTB drawings that occassionally need to be brought forward when projects get resurrected (state government highway designs are prone to getting shelved).

    Up to AutoCAD 2009, I've had a VBA routine that performed a few operations on a list of files stored in a text file:
    - Open the drawing file.
    - Convert to STB using "CONVERTPSTYLES" with a specified STB file.
    - Run a script to load a layer state file to change the plot styles from Style1, Style2 etc, to their correct named plot styles.
    - Manage a recalcitrant layer that refused to play ball.
    - Save and close the document
    - Get the next file........

    This was all fine until 2010 came along with the announcement that VBA was to be phased out. 2010 is OK with the VBA enablers, but now I've got some work to do.

    Our organisation's development language is C# and I'm using Visual Studio 2008 Professional Edition to develop my C# .NET code.

  2. #2
    Member
    Join Date
    2008-06
    Posts
    11
    Login to Give a bone
    0

    Default Re: Batch Converting CTB to STB

    Tony,

    It's amazing how if you write something down (i.e. plant a seed) and let it fester for a while, how your brain sometimes comes across these things in it's own good time.

    I thought of this one on the weekend before checking this forum this morning (Monday) and yes using the (command) option will work. So hurrah!!!!

    The problem I'm having now is getting .NET to wait for the file to be open and active before bouncing through to the convertpstyles command. It's a bit keen isn't it!!!

    I can get the file to open as per the .NET Developer's guide and this post on the Autodesk discussion groups, as a separate operation.

    I can also run convertpstyles on an already open file.

    I'm having great difficulty getting them to happen one after the other, waiting for each operation to finish.

    I've tried setting up a CommandEnded for both the FileOpen and convertpstyles operations.

    The FileOpen handler gets stepped into to launch the file open, but .NET doesn't wait around for the file to finish opening (and become active) before firing off the convertpstyles option.

    Although the convertpstyles handler gets stepped into to launch the convertpstyles command, the actual CommandEnded handler isn't being triggered until I close AutoCAD.

    It's all very frustrating. Essentially what I want to happen is:
    • Get the user to select a text file containing paths and file names to drawings that need to be processed. This can be generated by a simple "dir /b *.dwg > FileList.txt" command in a Windows command prompt window. It also allows the user to be selective about the files to be processed.
      • This bit's the easy part.
    • For each drawing in the drawing list:
      • Open the file
      • Run convertpstyles
      • Load a layer states file to set the plot styles correctly (I've found some code that should do this for me)
      • Save and Close the file
    It shouldn't be this hard!!!!

  3. #3
    Member
    Join Date
    2008-06
    Posts
    11
    Login to Give a bone
    0

    Default Re: Batch Converting CTB to STB

    Keeping it short and simple:

    Oh bugger!!!!

    I did find a LISP routine on "Through the interface" for stepping through files, but I'm having a bit of trouble getting it to behave as well.

    Could be to do with trying to modify code to do what I want it to do rather than what it was originall written to do.

    Oh well, I'll persist. I might trip over something else that helps me.

  4. #4
    Member
    Join Date
    2008-06
    Posts
    11
    Login to Give a bone
    0

    Default Re: Batch Converting CTB to STB

    I've persisted and come up with a solution that appears to work.

    I had trouble getting a pure AutoLISP option to work, the original batch file method I found processed an entire folder of drawings, and as documented above (below?) .NET wasn't working for me either.

    It's a "bitsa", made up of a bit of pure C# .NET, a bit of AutoLISP, a bit of scripting and a bit of .NET in AutoCAD. A bitsa....!!!

    The files I've provided in the attached zip file include:
    • A zipped Visual Studio 2008 solution (ConvertPstyles.zip) for the ConvertPstyles application. Excuse my icon (if you can see it), I'm rubbish at that stuff.
    • A zipped Visual Studio 2008 solution (ACADdotNetForCTB2STB.zip) for the ACADdotNetForCTB2STB.dll that needs to be loaded into AutoCAD. There is a netload command in the acadoc.lsp file below.
    • acadoc.lsp file containing the default entries from acad2010doc.lsp with the required commands added to the bottom.
    • Script file (Convert2STB.scr) used to perform the commands on each drawing file.
    • Text file (MR Standard Layer Definitions.txt) containing our layer definitions used when performing the compliance check in the script (i.e. CLS .NET command in the ACADdotNetForCTB2STB.dll) .
    • A PDF file "ConvertPstyles_Help.pdf explaining how it operates. References to system.lsp relate to how I've got my environment configured. The commands are provided here in the acaddoc.lsp file instead.
    I've had to pull some of the code included in the attached collection of files from a much larger customisation set to try and keep it relevant to this problem. I hope I haven't broken something.

    There are a few hard coded paths to files that you'll have to look for and change to suit your own needs. My closely controlled environment allows me the luxury of fixed paths. There are some places where the code searches for a folder, but again I know exactly what I'm looking for. You might need to change this.

    I hope that someone else is able to make sense of it and finds it useful.
    Attached Files Attached Files

  5. #5
    Member brantfetter's Avatar
    Join Date
    2005-02
    Posts
    22
    Login to Give a bone
    0

    Default Re: Batch Converting CTB to STB

    Brendon, Thanks for sharing your efforts. I'm astonished that there hasn't been more response to your thread. I'm looking a huge library that I need to update and I'm hoping this works. I'll post after having a go of it.

  6. #6
    Member brantfetter's Avatar
    Join Date
    2005-02
    Posts
    22
    Login to Give a bone
    0

    Default Re: Batch Converting CTB to STB

    I spent a little time poking through the package, and attempted to place the files in the right spots, but some simple information is missing. A list of each file or folder and the correct location would be very helpful (several locations are mentioned, but not all). Yes, I know, the .net stuff has a default location, but I don't remember where they all go. I'm comfortable with getting into the scripts and adjusting the referenced stb files to suit my needs or making up temporary fixed directories locations to suit the process is fine too. I'm just missing some basic information not in that informative PDF your office put out.

  7. #7
    Member
    Join Date
    2008-06
    Posts
    11
    Login to Give a bone
    0

    Default Re: Batch Converting CTB to STB

    Brant,

    Sorry I haven't responded to you. The lack of replies and my general "busyness" meant that I haven't looked at the forums for a while now.

    At the moment there is a hard coded registry path to our AutoCAD 2010 profile in the "GetScriptPath" subroutine of the "frmConvertPstyles" class in the .NET project.

    It shows up as:
    // Retrieve the "Support File Search Path" value from the Windows Registry.
    string FileSearchPaths = ReadRegistryValue.ReadRegValue("Current User", "Software\\Autodesk\\AutoCAD\\R18.0\\ACAD-8001:409\\Profiles\\MR_Standard_ACAD\\General", "ACAD");
    This pulls out all the file search paths that have been set up in the specified profile. In this case MR_Standard_ACAD.

    It then looks for acad2010\\scr in the string and uses the returned value as the script file path which is fed to the text field on the ConvertPstyles form. You should be able to overwrite this, although I haven't made any allowance for the registry location not existing. Oops.

    As stated, the batch file is created in the folder of the first drawing(s) selected when ConvertPstyles.exe is run, therefore paths don't matter to the batch file.

    All the drawings added to the batch file will have full path names, so they should be OK as well.

    ConvertPstyles.exe should be executable from anywhere on the local drive.

    The other LISP routines and scripts, simply need to be in your search paths.

    The acaddoc.lsp file provided is the standard file with the relevant code added to the bottom. If it's included in your search paths, AutoCAD will automatically load it.

    This will then perform the NETLOAD command to load the relevant dll.

    I hope I haven't left anything out. If so I'll keep a better eye on the forum to see if you need more info.

  8. #8
    Member
    Join Date
    2008-07
    Posts
    6
    Login to Give a bone
    0

    Default Re: Batch Converting CTB to STB

    Do I need special writes to download the zip file? I can't dowload it...

  9. #9
    Woo! Hoo! my 1st post
    Join Date
    2016-04
    Posts
    1
    Login to Give a bone
    0

    Default Re: Batch Converting CTB to STB

    I'm not very familiar with this kind of code or program. I use AutoCAD Electrical 2012 on Windows XP. I downloaded the ZIP file and I see that there are lots of files in there. I tried to run the Convertpstyles.exe but it is not working and it gives me a Windows error.

    I read the Convertpstyles_Help.PDF but I do not seem to understand everything. I would like to know the exact procedure to create a batch file.

    If anyone can help me, it would be appreciated !!

    Thank you!!

Similar Threads

  1. Converting batch dwg to dxf files with Windows 7 operating system
    By mikep.86877 in forum AutoCAD Customization
    Replies: 4
    Last Post: 2013-02-08, 10:16 PM
  2. 2012 batch converting dwg files to nwd or nwd
    By ndar in forum NavisWorks - General
    Replies: 1
    Last Post: 2013-02-01, 04:46 PM
  3. Batch Converting - PP sheets
    By randyspear in forum AutoCAD Civil 3D - General
    Replies: 0
    Last Post: 2008-07-15, 08:16 PM
  4. Batch Converting ABS 2007 to AutoCAD 2004
    By bbambu in forum AMEP General
    Replies: 2
    Last Post: 2007-05-23, 08:56 PM
  5. Batch purging/converting wanted!
    By asusca in forum Revit Architecture - General
    Replies: 2
    Last Post: 2005-12-30, 12:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •