Extract Objects into new drawing

Hello,

I spend alot of time extracting 3d solids, triangles(3d Faces) and 3d polylines from our design models and saving into separate files for sharing with other disciplines.

I have dynamo scripts that can extract this information but don’t know how to save into a blank drawing.
Is this currently possible with the nodes available?

Ideally i would like to be able to run the script and a file containing said objects would be created in a specified directory.

Thanks for any responses in advance

Hi @brett.townsend,

See if this helps, its a reply to similar query.

Hi @brett.townsend,

Many ways to do this. How about run a save as routine in the command line? See sample SaveAsRoutine+Prefix.dyn (4.4 KB)

Cheers,
Jowenn

2 Likes

Try this

# -*- coding: utf-8 -*-
"""
Created on Mon Aug 30 15:04:10 2021

@author: liconad
"""

# Load the Python Standard and DesignScript Libraries
import sys
import os
import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('System.Windows.Forms')

# Add references to manage arrays, collections and interact with the user
from System import *
from System.IO import *
from System.Collections.Specialized import *
from System.Windows.Forms import MessageBox

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Create an alias to the Autodesk.AutoCAD.ApplicationServices.Application class
import Autodesk.AutoCAD.ApplicationServices.Application as acapp

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

#Import references from 
import System
from System import *


#Establish global variables
aDoc = acapp.DocumentManager.MdiActiveDocument
cDoc = CivilApplication.ActiveDocument
ed = aDoc.Editor


def WBlock(path,oHand):
    """
	Create new drawing using WBlock method
	
	:path : filepath of new drawing to be created
    :oHand : Handle of pipe network to be exported 

	"""
    #call global variables inside the drawing
    global aDoc
    global cDoc
    global ed
 
    #Create an object id collection
    oic = ObjectIdCollection() 
    #Access the database
    with aDoc.Database as db:
        #Open transaction
        tr = db.TransactionManager.StartTransaction()
        with tr:
            #Get object ids (using handle)
            for handle in oHand :
                newhandleint = int(handle,16)
                hexa = Handle(newhandleint)
                oid = db.GetObjectId(False,hexa,oHand.index(handle))
                oic.Add(oid)
            #Create a new database
            with Database(True, False) as newdb:     
                #use WBlock method 
                db.Wblock(newdb, oic, Point3d.Origin, DuplicateRecordCloning.Ignore)
                #save new database as new drawing
                newdb.SaveAs(path, DwgVersion.Newest)
                return 'Completed'

WBlock(IN[0],IN[1])
5 Likes

Wow that’s powerful, thanks for sharing! Here’s .dyn for the next person.
SaveAs with Objects v0.dyn (12.3 KB)

Thanks David, this will be used in many work flows.

Sorry to add more query to this but select object by handle will it take dynamo representation also in to account ? Say the corridor featureline can be read in polycurve and no need to create polylines, take this polycurve directly to new drawing as a autocad lines.

Just trying to simplify export for construction or export to CAD task of Civil 3D.

Hi Shahid, if you select the corridor featureline from the drawing then yes it will export it (you can select it graphically as with the example or going through the corridor nodes/objects by layer)… if for example you brought the corridor featureline, created a dynamo proxy as a polycurve and made changes in the dynamospace then you will need to send this to Civil 3D before being able to export the updated geometry. How the node works is that you need an object already in the database for it to be exported, it is not creating any new geometry. Hope that helps.

1 Like

Yes clear now.
I was hoping to find a solution which wont need to create a CAD entity in the same model file and then export it using dynamo.

anyway thanks for this script this will save lot of time for selection of entity (filtering based on dynamo conditions) from one file and saveas to other file.

Well it depends on your workflow but there are 2 things to consider here :

  1. You can always create the entity in the original file in say a specific temporary layer, select all things in that layer and export it using the node above and then using dynamo to delete those objects so it is transparent for the user
  2. it should be possible to add entities to the newly created database (newdb) it will just take much more python scripting, specially if you will be adding different types of entities. As a disclaimer, I haven’t tried this :slight_smile:
1 Like