added Revit 2022 SDK minus except *rvt and *rfa

This commit is contained in:
Jeremy Tammik
2021-04-20 11:36:21 +02:00
parent 1133a82dc5
commit 7e327986e8
3034 changed files with 1245318 additions and 0 deletions
@@ -0,0 +1,630 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.ImportExport.CS
{
/// <summary>
/// Data class which stores the information for importing dwg format
/// </summary>
public class ImportDWGData : ImportData
{
#region Class Member Variables
/// <summary>
/// ThisViewOnly
/// </summary>
private bool m_importThisViewOnly;
/// <summary>
/// All views
/// </summary>
private ViewSet m_views;
/// <summary>
/// Import view
/// </summary>
private View m_importView;
/// <summary>
/// ColorMode for import
/// </summary>
private List<String> m_colorMode;
/// <summary>
/// All available import color modes
/// </summary>
private List<Autodesk.Revit.DB.ImportColorMode> m_enumColorMode;
/// <summary>
/// Import color mode
/// </summary>
private Autodesk.Revit.DB.ImportColorMode m_importColorMode;
/// <summary>
/// Custom scale for import
/// </summary>
private double m_importCustomScale;
/// <summary>
/// OrientToView
/// </summary>
private bool m_importOrientToView;
/// <summary>
/// Placement
/// </summary>
private List<String> m_placement;
/// <summary>
/// All placement for layers to be imported
/// </summary>
private List<Autodesk.Revit.DB.ImportPlacement> m_enumPlacement;
/// <summary>
/// Placement for import
/// </summary>
private Autodesk.Revit.DB.ImportPlacement m_importPlacement;
/// <summary>
/// All units for layer to be imported
/// </summary>
private List<String> m_unit;
/// <summary>
/// All import unit for import layers
/// </summary>
private List<Autodesk.Revit.DB.ImportUnit> m_enumUnit;
/// <summary>
/// Import unit
/// </summary>
private Autodesk.Revit.DB.ImportUnit m_importUnit;
/// <summary>
/// All available layers only
/// </summary>
private List<String> m_visibleLayersOnly;
/// <summary>
/// All boolean values for available visible layers
/// </summary>
private List<bool> m_enumVisibleLayersOnly;
/// <summary>
/// Whether import visible layer only
/// </summary>
private bool m_importVisibleLayersOnly;
/// <summary>
/// Whether active view is 3D
/// </summary>
private bool m_is3DView;
#endregion
#region Class Properties
/// <summary>
/// Get or set whether import this view only
/// </summary>
public bool ImportThisViewOnly
{
get
{
return m_importThisViewOnly;
}
set
{
m_importThisViewOnly = value;
}
}
/// <summary>
/// all views for import
/// </summary>
public ViewSet Views
{
get
{
return m_views;
}
set
{
m_views = value;
}
}
/// <summary>
/// Import view
/// </summary>
public View ImportView
{
get
{
return m_importView;
}
set
{
m_importView = value;
}
}
/// <summary>
/// All available color modes for import
/// </summary>
public ReadOnlyCollection<String> ColorMode
{
get
{
return new ReadOnlyCollection<String>(m_colorMode);
}
}
/// <summary>
/// All available import color modes
/// </summary>
public ReadOnlyCollection<Autodesk.Revit.DB.ImportColorMode> EnumColorMode
{
get
{
return new ReadOnlyCollection<Autodesk.Revit.DB.ImportColorMode>(m_enumColorMode);
}
}
/// <summary>
/// Import color mode
/// </summary>
public Autodesk.Revit.DB.ImportColorMode ImportColorMode
{
get
{
return m_importColorMode;
}
set
{
m_importColorMode = value;
}
}
/// <summary>
/// Custom scale for import
/// </summary>
public double ImportCustomScale
{
get
{
return m_importCustomScale;
}
set
{
m_importCustomScale = value;
}
}
/// <summary>
/// Whether import orient to view
/// </summary>
public bool ImportOrientToView
{
get
{
return m_importOrientToView;
}
set
{
m_importOrientToView = value;
}
}
/// <summary>
/// All placement for layers to be imported
/// </summary>
public ReadOnlyCollection<String> Placement
{
get
{
return new ReadOnlyCollection<String>(m_placement);
}
}
/// <summary>
/// All ImportPlacements for all layers to be imported
/// </summary>
public ReadOnlyCollection<Autodesk.Revit.DB.ImportPlacement> EnumPlacement
{
get
{
return new ReadOnlyCollection<Autodesk.Revit.DB.ImportPlacement>(m_enumPlacement);
}
}
/// <summary>
/// Import placement for import
/// </summary>
public Autodesk.Revit.DB.ImportPlacement ImportPlacement
{
get
{
return m_importPlacement;
}
set
{
m_importPlacement = value;
}
}
/// <summary>
/// All units for layer to be imported
/// </summary>
public ReadOnlyCollection<String> Unit
{
get
{
return new ReadOnlyCollection<string>(m_unit);
}
}
/// <summary>
/// All import unit for import layers
/// </summary>
public ReadOnlyCollection<Autodesk.Revit.DB.ImportUnit> EnumUnit
{
get
{
return new ReadOnlyCollection<Autodesk.Revit.DB.ImportUnit>(m_enumUnit);
}
}
/// <summary>
/// Get or set import unit
/// </summary>
public Autodesk.Revit.DB.ImportUnit ImportUnit
{
get
{
return m_importUnit;
}
set
{
m_importUnit = value;
}
}
/// <summary>
/// All available layers only
/// </summary>
public ReadOnlyCollection<String> VisibleLayersOnly
{
get
{
return new ReadOnlyCollection<String>(m_visibleLayersOnly);
}
}
/// <summary>
/// All boolean values for available visible layers
/// </summary>
public ReadOnlyCollection<bool> EnumVisibleLayersOnly
{
get
{
return new ReadOnlyCollection<bool>(m_enumVisibleLayersOnly);
}
}
/// <summary>
/// Whether import visible layer only
/// </summary>
public bool ImportVisibleLayersOnly
{
get
{
return m_importVisibleLayersOnly;
}
set
{
m_importVisibleLayersOnly = value;
}
}
/// <summary>
/// Whether active view is 3D
/// </summary>
public bool Is3DView
{
get
{
return m_is3DView;
}
set
{
m_is3DView = value;
}
}
#endregion
#region Class Member Methods
/// <summary>
/// Constructor
/// </summary>
/// <param name="commandData">Revit command data</param>
/// <param name="format">Format to import</param>
public ImportDWGData(ExternalCommandData commandData, ImportFormat format)
: base(commandData, format)
{
Initialize();
}
/// <summary>
/// Collect the parameters and export
/// </summary>
/// <returns></returns>
public override bool Import()
{
bool imported = false;
//parameter: DWGImportOptions
DWGImportOptions dwgImportOption = new DWGImportOptions();
dwgImportOption.ColorMode = m_importColorMode;
dwgImportOption.CustomScale = m_importCustomScale;
dwgImportOption.OrientToView = m_importOrientToView;
dwgImportOption.Placement = m_importPlacement;
dwgImportOption.ThisViewOnly = m_importThisViewOnly;
View view = null;
if (!m_importThisViewOnly)
{
view = m_importView;
}
else
{
view = m_activeDoc.ActiveView;
}
dwgImportOption.Unit = m_importUnit;
dwgImportOption.VisibleLayersOnly = m_importVisibleLayersOnly;
//parameter: ElementId
ElementId elementId = null;
//Import
Transaction t = new Transaction(m_activeDoc);
t.SetName("Import");
t.Start();
imported = m_activeDoc.Import(m_importFileFullName, dwgImportOption, view, out elementId);
t.Commit();
return imported;
}
#endregion
#region Class Implementation
/// <summary>
/// Initialize the variables
/// </summary>
private void Initialize()
{
//ColorMode
m_colorMode = new List<String>();
m_enumColorMode = new List<Autodesk.Revit.DB.ImportColorMode>();
m_colorMode.Add("Black and white");
m_enumColorMode.Add(Autodesk.Revit.DB.ImportColorMode.BlackAndWhite);
m_colorMode.Add("Preserve colors");
m_enumColorMode.Add(Autodesk.Revit.DB.ImportColorMode.Preserved);
m_colorMode.Add("Invert colors");
m_enumColorMode.Add(Autodesk.Revit.DB.ImportColorMode.Inverted);
//Placement
m_placement = new List<String>();
m_enumPlacement = new List<Autodesk.Revit.DB.ImportPlacement>();
m_placement.Add("Center-to-center");
m_enumPlacement.Add(Autodesk.Revit.DB.ImportPlacement.Centered);
m_placement.Add("Origin-to-origin");
m_enumPlacement.Add(Autodesk.Revit.DB.ImportPlacement.Origin);
//Unit
m_unit = new List<String>();
m_enumUnit = new List<Autodesk.Revit.DB.ImportUnit>();
m_unit.Add("Auto-Detect");
m_enumUnit.Add(Autodesk.Revit.DB.ImportUnit.Default);
m_unit.Add(Autodesk.Revit.DB.ImportUnit.Foot.ToString());
m_enumUnit.Add(Autodesk.Revit.DB.ImportUnit.Foot);
m_unit.Add(Autodesk.Revit.DB.ImportUnit.Inch.ToString());
m_enumUnit.Add(Autodesk.Revit.DB.ImportUnit.Inch);
m_unit.Add(Autodesk.Revit.DB.ImportUnit.Meter.ToString());
m_enumUnit.Add(Autodesk.Revit.DB.ImportUnit.Meter);
m_unit.Add(Autodesk.Revit.DB.ImportUnit.Decimeter.ToString());
m_enumUnit.Add(Autodesk.Revit.DB.ImportUnit.Decimeter);
m_unit.Add(Autodesk.Revit.DB.ImportUnit.Centimeter.ToString());
m_enumUnit.Add(Autodesk.Revit.DB.ImportUnit.Centimeter);
m_unit.Add(Autodesk.Revit.DB.ImportUnit.Millimeter.ToString());
m_enumUnit.Add(Autodesk.Revit.DB.ImportUnit.Millimeter);
m_unit.Add("Custom");
m_enumUnit.Add(Autodesk.Revit.DB.ImportUnit.Default);
//VisibleLayersOnly
m_visibleLayersOnly = new List<String>();
m_enumVisibleLayersOnly = new List<bool>();
m_visibleLayersOnly.Add("All");
m_enumVisibleLayersOnly.Add(false);
m_visibleLayersOnly.Add("Visible");
m_enumVisibleLayersOnly.Add(true);
//Whether active view is 3D
m_is3DView = false;
if (m_activeDoc.ActiveView.ViewType == Autodesk.Revit.DB.ViewType.ThreeD)
{
m_is3DView = true;
}
//Views
m_views = new ViewSet();
GetViews();
m_importCustomScale = 0.0;
m_importOrientToView = true;
m_importUnit = Autodesk.Revit.DB.ImportUnit.Default;
m_importThisViewOnly = false;
m_importView = m_activeDoc.ActiveView;
m_importColorMode = Autodesk.Revit.DB.ImportColorMode.Inverted;
m_importPlacement = Autodesk.Revit.DB.ImportPlacement.Centered;
m_importVisibleLayersOnly = false;
m_filter = "DWG Files (*.dwg)|*.dwg";
m_title = "Import DWG";
}
/// <summary>
/// Get all the views to be displayed
/// </summary>
private void GetViews()
{
FilteredElementCollector collector = new FilteredElementCollector(m_activeDoc);
FilteredElementIterator itor = collector.OfClass(typeof(View)).GetElementIterator();
itor.Reset();
ViewSet views = new ViewSet();
ViewSet floorPlans = new ViewSet();
ViewSet ceilingPlans = new ViewSet();
ViewSet engineeringPlans = new ViewSet();
while (itor.MoveNext())
{
View view = itor.Current as View;
// skip view templates because they're invalid for import/export
if (view == null || view.IsTemplate)
{
continue;
}
else if (view.ViewType == Autodesk.Revit.DB.ViewType.FloorPlan)
{
floorPlans.Insert(view);
}
else if (view.ViewType == Autodesk.Revit.DB.ViewType.CeilingPlan)
{
ceilingPlans.Insert(view);
}
else if (view.ViewType == Autodesk.Revit.DB.ViewType.EngineeringPlan)
{
engineeringPlans.Insert(view);
}
}
foreach (View floorPlan in floorPlans)
{
foreach (View ceilingPlan in ceilingPlans)
{
if (floorPlan.Name == ceilingPlan.Name)
{
views.Insert(floorPlan);
}
}
}
foreach (View engineeringPlan in engineeringPlans)
{
if (engineeringPlan.Name == engineeringPlan.GenLevel.Name)
{
views.Insert(engineeringPlan);
}
}
View activeView = m_activeDoc.ActiveView;
Autodesk.Revit.DB.ViewType viewType = activeView.ViewType;
if (viewType == Autodesk.Revit.DB.ViewType.FloorPlan ||
viewType == Autodesk.Revit.DB.ViewType.CeilingPlan)
{
m_views.Insert(activeView);
foreach (View view in views)
{
if (view.GenLevel.Elevation < activeView.GenLevel.Elevation)
{
m_views.Insert(view);
}
}
}
else if (viewType == Autodesk.Revit.DB.ViewType.EngineeringPlan)
{
if (views.Contains(activeView))
{
m_views.Insert(activeView);
}
foreach (View view in views)
{
if (view.GenLevel.Elevation < activeView.GenLevel.Elevation)
{
m_views.Insert(view);
}
}
}
else//Get view of the lowest elevation
{
int i = 0;
double elevation = 0;
View viewLowestElevation = null;
foreach (View view in views)
{
if (i == 0)
{
elevation = view.GenLevel.Elevation;
viewLowestElevation = view;
}
else
{
if (view.GenLevel.Elevation <= elevation)
{
elevation = view.GenLevel.Elevation;
viewLowestElevation = view;
}
}
i++;
}
m_views.Insert(viewLowestElevation);
}
}
#endregion
}
}
@@ -0,0 +1,397 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
namespace Revit.SDK.Samples.ImportExport.CS
{
/// <summary>
/// It contains a dialog which provides the options of import
/// </summary>
partial class ImportDWGForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOpen = new System.Windows.Forms.Button();
this.labelFileName = new System.Windows.Forms.Label();
this.textBoxFileSource = new System.Windows.Forms.TextBox();
this.buttonBrowser = new System.Windows.Forms.Button();
this.groupBoxPositioning = new System.Windows.Forms.GroupBox();
this.labelAutomaticallyPlace = new System.Windows.Forms.Label();
this.labelPlaceLevel = new System.Windows.Forms.Label();
this.radioButtonOrigin2Origin = new System.Windows.Forms.RadioButton();
this.radioButtonCenter2Center = new System.Windows.Forms.RadioButton();
this.comboBoxLevel = new System.Windows.Forms.ComboBox();
this.checkBoxOrient2View = new System.Windows.Forms.CheckBox();
this.groupBoxScaling = new System.Windows.Forms.GroupBox();
this.comboBoxUnits = new System.Windows.Forms.ComboBox();
this.textBoxScale = new System.Windows.Forms.TextBox();
this.labelScaleFactor = new System.Windows.Forms.Label();
this.labelUnits = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.radioButtonInvertColor = new System.Windows.Forms.RadioButton();
this.radioButtonPreserve = new System.Windows.Forms.RadioButton();
this.radioButtonBlackWhite = new System.Windows.Forms.RadioButton();
this.checkBoxCurrentViewOnly = new System.Windows.Forms.CheckBox();
this.comboBoxLayers = new System.Windows.Forms.ComboBox();
this.labelLayers = new System.Windows.Forms.Label();
this.groupBoxPositioning.SuspendLayout();
this.groupBoxScaling.SuspendLayout();
this.groupBoxColors.SuspendLayout();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(390, 285);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 21);
this.buttonCancel.TabIndex = 8;
this.buttonCancel.Text = "&Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// buttonOpen
//
this.buttonOpen.Location = new System.Drawing.Point(303, 285);
this.buttonOpen.Name = "buttonOpen";
this.buttonOpen.Size = new System.Drawing.Size(75, 21);
this.buttonOpen.TabIndex = 7;
this.buttonOpen.Text = "&Open";
this.buttonOpen.UseVisualStyleBackColor = true;
this.buttonOpen.Click += new System.EventHandler(this.buttonOpen_Click);
//
// labelFileName
//
this.labelFileName.AutoSize = true;
this.labelFileName.Location = new System.Drawing.Point(10, 15);
this.labelFileName.Name = "labelFileName";
this.labelFileName.Size = new System.Drawing.Size(61, 13);
this.labelFileName.TabIndex = 10;
this.labelFileName.Text = "File source:";
//
// textBoxFileSource
//
this.textBoxFileSource.Location = new System.Drawing.Point(73, 11);
this.textBoxFileSource.Name = "textBoxFileSource";
this.textBoxFileSource.Size = new System.Drawing.Size(369, 20);
this.textBoxFileSource.TabIndex = 1;
//
// buttonBrowser
//
this.buttonBrowser.Location = new System.Drawing.Point(442, 11);
this.buttonBrowser.Name = "buttonBrowser";
this.buttonBrowser.Size = new System.Drawing.Size(24, 20);
this.buttonBrowser.TabIndex = 0;
this.buttonBrowser.Text = "...";
this.buttonBrowser.UseVisualStyleBackColor = true;
this.buttonBrowser.Click += new System.EventHandler(this.buttonBrowser_Click);
//
// groupBoxPositioning
//
this.groupBoxPositioning.Controls.Add(this.labelAutomaticallyPlace);
this.groupBoxPositioning.Controls.Add(this.labelPlaceLevel);
this.groupBoxPositioning.Controls.Add(this.radioButtonOrigin2Origin);
this.groupBoxPositioning.Controls.Add(this.radioButtonCenter2Center);
this.groupBoxPositioning.Controls.Add(this.comboBoxLevel);
this.groupBoxPositioning.Controls.Add(this.checkBoxOrient2View);
this.groupBoxPositioning.Location = new System.Drawing.Point(229, 43);
this.groupBoxPositioning.Name = "groupBoxPositioning";
this.groupBoxPositioning.Size = new System.Drawing.Size(237, 157);
this.groupBoxPositioning.TabIndex = 5;
this.groupBoxPositioning.TabStop = false;
this.groupBoxPositioning.Text = "Positioning";
//
// labelAutomaticallyPlace
//
this.labelAutomaticallyPlace.AutoSize = true;
this.labelAutomaticallyPlace.Location = new System.Drawing.Point(15, 18);
this.labelAutomaticallyPlace.Name = "labelAutomaticallyPlace";
this.labelAutomaticallyPlace.Size = new System.Drawing.Size(98, 13);
this.labelAutomaticallyPlace.TabIndex = 0;
this.labelAutomaticallyPlace.Text = "Automatically place";
//
// labelPlaceLevel
//
this.labelPlaceLevel.AutoSize = true;
this.labelPlaceLevel.Location = new System.Drawing.Point(14, 129);
this.labelPlaceLevel.Name = "labelPlaceLevel";
this.labelPlaceLevel.Size = new System.Drawing.Size(74, 13);
this.labelPlaceLevel.TabIndex = 5;
this.labelPlaceLevel.Text = "Place at level:";
//
// radioButtonOrigin2Origin
//
this.radioButtonOrigin2Origin.AutoSize = true;
this.radioButtonOrigin2Origin.Location = new System.Drawing.Point(19, 60);
this.radioButtonOrigin2Origin.Name = "radioButtonOrigin2Origin";
this.radioButtonOrigin2Origin.Size = new System.Drawing.Size(92, 17);
this.radioButtonOrigin2Origin.TabIndex = 2;
this.radioButtonOrigin2Origin.TabStop = true;
this.radioButtonOrigin2Origin.Text = "Origin-to-origin";
this.radioButtonOrigin2Origin.UseVisualStyleBackColor = true;
//
// radioButtonCenter2Center
//
this.radioButtonCenter2Center.AutoSize = true;
this.radioButtonCenter2Center.Checked = true;
this.radioButtonCenter2Center.Location = new System.Drawing.Point(19, 37);
this.radioButtonCenter2Center.Name = "radioButtonCenter2Center";
this.radioButtonCenter2Center.Size = new System.Drawing.Size(101, 17);
this.radioButtonCenter2Center.TabIndex = 1;
this.radioButtonCenter2Center.TabStop = true;
this.radioButtonCenter2Center.Text = "Center-to-center";
this.radioButtonCenter2Center.UseVisualStyleBackColor = true;
//
// comboBoxLevel
//
this.comboBoxLevel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxLevel.FormattingEnabled = true;
this.comboBoxLevel.Location = new System.Drawing.Point(91, 125);
this.comboBoxLevel.Name = "comboBoxLevel";
this.comboBoxLevel.Size = new System.Drawing.Size(122, 21);
this.comboBoxLevel.TabIndex = 4;
//
// checkBoxOrient2View
//
this.checkBoxOrient2View.AutoSize = true;
this.checkBoxOrient2View.Checked = true;
this.checkBoxOrient2View.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxOrient2View.Location = new System.Drawing.Point(17, 104);
this.checkBoxOrient2View.Name = "checkBoxOrient2View";
this.checkBoxOrient2View.Size = new System.Drawing.Size(92, 17);
this.checkBoxOrient2View.TabIndex = 3;
this.checkBoxOrient2View.Text = "Orient to View";
this.checkBoxOrient2View.UseVisualStyleBackColor = true;
//
// groupBoxScaling
//
this.groupBoxScaling.Controls.Add(this.comboBoxUnits);
this.groupBoxScaling.Controls.Add(this.textBoxScale);
this.groupBoxScaling.Controls.Add(this.labelScaleFactor);
this.groupBoxScaling.Controls.Add(this.labelUnits);
this.groupBoxScaling.Location = new System.Drawing.Point(10, 202);
this.groupBoxScaling.Name = "groupBoxScaling";
this.groupBoxScaling.Size = new System.Drawing.Size(456, 50);
this.groupBoxScaling.TabIndex = 6;
this.groupBoxScaling.TabStop = false;
this.groupBoxScaling.Text = "Scaling";
//
// comboBoxUnits
//
this.comboBoxUnits.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxUnits.FormattingEnabled = true;
this.comboBoxUnits.Location = new System.Drawing.Point(79, 18);
this.comboBoxUnits.Name = "comboBoxUnits";
this.comboBoxUnits.Size = new System.Drawing.Size(121, 21);
this.comboBoxUnits.TabIndex = 0;
this.comboBoxUnits.SelectedIndexChanged += new System.EventHandler(this.comboBoxUnits_SelectedIndexChanged);
//
// textBoxScale
//
this.textBoxScale.Enabled = false;
this.textBoxScale.Location = new System.Drawing.Point(310, 19);
this.textBoxScale.Name = "textBoxScale";
this.textBoxScale.Size = new System.Drawing.Size(122, 20);
this.textBoxScale.TabIndex = 1;
this.textBoxScale.Text = 1.0.ToString("0.000000");
this.textBoxScale.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxScale_KeyPress);
this.textBoxScale.TextChanged += new System.EventHandler(this.textBoxScale_TextChanged);
//
// labelScaleFactor
//
this.labelScaleFactor.AutoSize = true;
this.labelScaleFactor.Location = new System.Drawing.Point(234, 22);
this.labelScaleFactor.Name = "labelScaleFactor";
this.labelScaleFactor.Size = new System.Drawing.Size(67, 13);
this.labelScaleFactor.TabIndex = 2;
this.labelScaleFactor.Text = "Scale factor:";
//
// labelUnits
//
this.labelUnits.AutoSize = true;
this.labelUnits.Location = new System.Drawing.Point(7, 22);
this.labelUnits.Name = "labelUnits";
this.labelUnits.Size = new System.Drawing.Size(64, 13);
this.labelUnits.TabIndex = 0;
this.labelUnits.Text = "Import units:";
//
// groupBoxColors
//
this.groupBoxColors.Controls.Add(this.radioButtonInvertColor);
this.groupBoxColors.Controls.Add(this.radioButtonPreserve);
this.groupBoxColors.Controls.Add(this.radioButtonBlackWhite);
this.groupBoxColors.Location = new System.Drawing.Point(10, 43);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Size = new System.Drawing.Size(200, 95);
this.groupBoxColors.TabIndex = 2;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Layer/Level Colors";
//
// radioButtonInvertColor
//
this.radioButtonInvertColor.AutoSize = true;
this.radioButtonInvertColor.Checked = true;
this.radioButtonInvertColor.Location = new System.Drawing.Point(14, 66);
this.radioButtonInvertColor.Name = "radioButtonInvertColor";
this.radioButtonInvertColor.Size = new System.Drawing.Size(83, 17);
this.radioButtonInvertColor.TabIndex = 2;
this.radioButtonInvertColor.TabStop = true;
this.radioButtonInvertColor.Text = "Invert colors";
this.radioButtonInvertColor.UseVisualStyleBackColor = true;
//
// radioButtonPreserve
//
this.radioButtonPreserve.AutoSize = true;
this.radioButtonPreserve.Location = new System.Drawing.Point(14, 43);
this.radioButtonPreserve.Name = "radioButtonPreserve";
this.radioButtonPreserve.Size = new System.Drawing.Size(98, 17);
this.radioButtonPreserve.TabIndex = 1;
this.radioButtonPreserve.Text = "Preserve colors";
this.radioButtonPreserve.UseVisualStyleBackColor = true;
//
// radioButtonBlackWhite
//
this.radioButtonBlackWhite.AutoSize = true;
this.radioButtonBlackWhite.Location = new System.Drawing.Point(15, 20);
this.radioButtonBlackWhite.Name = "radioButtonBlackWhite";
this.radioButtonBlackWhite.Size = new System.Drawing.Size(101, 17);
this.radioButtonBlackWhite.TabIndex = 0;
this.radioButtonBlackWhite.Text = "Black and white";
this.radioButtonBlackWhite.UseVisualStyleBackColor = true;
//
// checkBoxCurrentViewOnly
//
this.checkBoxCurrentViewOnly.AutoSize = true;
this.checkBoxCurrentViewOnly.Location = new System.Drawing.Point(17, 147);
this.checkBoxCurrentViewOnly.Name = "checkBoxCurrentViewOnly";
this.checkBoxCurrentViewOnly.Size = new System.Drawing.Size(107, 17);
this.checkBoxCurrentViewOnly.TabIndex = 3;
this.checkBoxCurrentViewOnly.Text = "Current view only";
this.checkBoxCurrentViewOnly.UseVisualStyleBackColor = true;
this.checkBoxCurrentViewOnly.CheckedChanged += new System.EventHandler(this.checkBoxCurrentViewOnly_CheckedChanged);
//
// comboBoxLayers
//
this.comboBoxLayers.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxLayers.FormattingEnabled = true;
this.comboBoxLayers.Location = new System.Drawing.Point(88, 168);
this.comboBoxLayers.Name = "comboBoxLayers";
this.comboBoxLayers.Size = new System.Drawing.Size(122, 21);
this.comboBoxLayers.TabIndex = 4;
//
// labelLayers
//
this.labelLayers.AutoSize = true;
this.labelLayers.Location = new System.Drawing.Point(14, 172);
this.labelLayers.Name = "labelLayers";
this.labelLayers.Size = new System.Drawing.Size(41, 13);
this.labelLayers.TabIndex = 5;
this.labelLayers.Text = "Layers:";
//
// ImportDWGForm
//
this.AcceptButton = this.buttonOpen;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(480, 316);
this.Controls.Add(this.checkBoxCurrentViewOnly);
this.Controls.Add(this.groupBoxPositioning);
this.Controls.Add(this.labelLayers);
this.Controls.Add(this.groupBoxScaling);
this.Controls.Add(this.groupBoxColors);
this.Controls.Add(this.buttonBrowser);
this.Controls.Add(this.comboBoxLayers);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOpen);
this.Controls.Add(this.labelFileName);
this.Controls.Add(this.textBoxFileSource);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ImportDWGForm";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Import";
this.groupBoxPositioning.ResumeLayout(false);
this.groupBoxPositioning.PerformLayout();
this.groupBoxScaling.ResumeLayout(false);
this.groupBoxScaling.PerformLayout();
this.groupBoxColors.ResumeLayout(false);
this.groupBoxColors.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Button buttonOpen;
private System.Windows.Forms.Label labelFileName;
private System.Windows.Forms.TextBox textBoxFileSource;
private System.Windows.Forms.Button buttonBrowser;
private System.Windows.Forms.GroupBox groupBoxPositioning;
private System.Windows.Forms.RadioButton radioButtonOrigin2Origin;
private System.Windows.Forms.RadioButton radioButtonCenter2Center;
private System.Windows.Forms.CheckBox checkBoxCurrentViewOnly;
private System.Windows.Forms.ComboBox comboBoxLevel;
private System.Windows.Forms.CheckBox checkBoxOrient2View;
private System.Windows.Forms.GroupBox groupBoxScaling;
private System.Windows.Forms.TextBox textBoxScale;
private System.Windows.Forms.Label labelScaleFactor;
private System.Windows.Forms.Label labelUnits;
private System.Windows.Forms.GroupBox groupBoxColors;
private System.Windows.Forms.RadioButton radioButtonInvertColor;
private System.Windows.Forms.RadioButton radioButtonPreserve;
private System.Windows.Forms.RadioButton radioButtonBlackWhite;
private System.Windows.Forms.Label labelAutomaticallyPlace;
private System.Windows.Forms.Label labelPlaceLevel;
private System.Windows.Forms.ComboBox comboBoxUnits;
private System.Windows.Forms.ComboBox comboBoxLayers;
private System.Windows.Forms.Label labelLayers;
}
}
@@ -0,0 +1,362 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.IO;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.ImportExport.CS
{
/// <summary>
/// It contains a dialog which provides the options of importing dwg format
/// </summary>
public partial class ImportDWGForm : System.Windows.Forms.Form
{
/// <summary>
/// Data class
/// </summary>
ImportDWGData m_importData;
/// <summary>
/// Constructor
/// </summary>
/// <param name="importData"></param>
public ImportDWGForm(ImportDWGData importData)
{
InitializeComponent();
m_importData = importData;
InitializeControls();
}
/// <summary>
/// Change the status of checkBoxOrient2View and comboBoxLevel according to the selection
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void checkBoxCurrentViewOnly_CheckedChanged(object sender, EventArgs e)
{
bool currentViewOnly = checkBoxCurrentViewOnly.Checked;
checkBoxOrient2View.Enabled = !currentViewOnly;
comboBoxLevel.Enabled = !currentViewOnly;
}
/// <summary>
/// Initialize values and status of controls
/// </summary>
private void InitializeControls()
{
//Layers
foreach (String layer in m_importData.VisibleLayersOnly)
{
comboBoxLayers.Items.Add(layer);
}
comboBoxLayers.SelectedIndex = 0;
//unit
foreach (String unit in m_importData.Unit)
{
comboBoxUnits.Items.Add(unit);
}
comboBoxUnits.SelectedIndex = 0;
//Level
foreach (Autodesk.Revit.DB.View view in m_importData.Views)
{
comboBoxLevel.Items.Add(view.Name);
}
comboBoxLevel.SelectedIndex = 0;
//If active view is 3D
if (m_importData.Is3DView)
{
checkBoxCurrentViewOnly.Checked = false;
checkBoxCurrentViewOnly.Enabled = false;
}
this.Text = m_importData.Title;
}
/// <summary>
/// Specify a file to export from
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonBrowser_Click(object sender, EventArgs e)
{
String returnFileFullName = String.Empty;
if (MainData.ShowOpenDialog(m_importData, ref returnFileFullName) != DialogResult.Cancel)
{
textBoxFileSource.Text = returnFileFullName;
}
}
/// <summary>
/// Change the status of textBoxScale according to the selection
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBoxUnits_SelectedIndexChanged(object sender, EventArgs e)
{
bool custom = comboBoxUnits.SelectedIndex == 7;
textBoxScale.Enabled = custom;
}
/// <summary>
/// Transfer information back to ImportData class and execute IMPORT operation
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonOpen_Click(object sender, EventArgs e)
{
if (ValidateFileName())
{
//Color Mode
SetImportColorMode();
//Placement
SetImportPlacement();
//Current view only, Orient to view, view to import into
SetImportViewsRelated();
//Visible layers only
SetImportLayers();
//Unit, scaling
SetImportUnitsAndScaling();
//Import
try
{
if (!m_importData.Import())
{
TaskDialog.Show("Import", "Cannot import " + Path.GetFileName(m_importData.ImportFileFullName) +
" in current settings.", TaskDialogCommonButtons.Ok);
}
}
catch (Exception ex)
{
TaskDialog.Show("Import Failed", ex.ToString(), TaskDialogCommonButtons.Ok);
}
this.DialogResult = DialogResult.OK;
this.Close();
}
}
/// <summary>
/// Validate the file to import
/// </summary>
/// <returns></returns>
private Boolean ValidateFileName()
{
String fileNameFull = textBoxFileSource.Text;
//If the textBoxFileSource is empty
if (String.IsNullOrEmpty(fileNameFull))
{
TaskDialog.Show("Information", "Please specify the folder and file name!", TaskDialogCommonButtons.Ok);
textBoxFileSource.Focus();
return false;
}
if (!File.Exists(fileNameFull))
{
TaskDialog.Show("Information", "Please specify an existing file!", TaskDialogCommonButtons.Ok);
textBoxFileSource.Focus();
return false;
}
m_importData.ImportFileFullName = fileNameFull;
return true;
}
/// <summary>
/// Set the value of color mode
/// </summary>
private void SetImportColorMode()
{
String colorMode;
if (radioButtonBlackWhite.Checked)
{
colorMode = radioButtonBlackWhite.Text;
}
else if (radioButtonPreserve.Checked)
{
colorMode = radioButtonPreserve.Text;
}
else
{
colorMode = radioButtonInvertColor.Text;
}
int indexColor = 0;
for (int i = 0; i < m_importData.ColorMode.Count; ++i)
{
if (colorMode == m_importData.ColorMode[i])
{
indexColor = i;
break;
}
}
m_importData.ImportColorMode = m_importData.EnumColorMode[indexColor];
}
/// <summary>
/// Set the value of placement
/// </summary>
private void SetImportPlacement()
{
String placement;
if (radioButtonCenter2Center.Checked)
{
placement = radioButtonCenter2Center.Text;
}
else
{
placement = radioButtonOrigin2Origin.Text;
}
int indexPlacement = 0;
for (int i = 0; i < m_importData.Placement.Count; ++i)
{
if (placement == m_importData.Placement[i])
{
indexPlacement = i;
break;
}
}
m_importData.ImportPlacement = m_importData.EnumPlacement[indexPlacement];
}
/// <summary>
/// Set the value of ImportThisViewOnly, ImportOrientToView, ImportView
/// </summary>
private void SetImportViewsRelated()
{
if (checkBoxCurrentViewOnly.Checked)
{
m_importData.ImportThisViewOnly = true;
}
else
{
m_importData.ImportThisViewOnly = false;
m_importData.ImportOrientToView = checkBoxOrient2View.Checked;
String viewName = comboBoxLevel.SelectedItem.ToString();
foreach (Autodesk.Revit.DB.View view in m_importData.Views)
{
if (viewName == view.Name)
{
m_importData.ImportView = view;
break;
}
}
}
}
/// <summary>
/// Set the value of ImportVisibleLayersOnly
/// </summary>
private void SetImportLayers()
{
//comboBoxLayers
m_importData.ImportVisibleLayersOnly = m_importData.EnumVisibleLayersOnly[comboBoxLayers.SelectedIndex];
}
/// <summary>
/// Set the value of unit, scaling
/// </summary>
private void SetImportUnitsAndScaling()
{
bool custom = comboBoxUnits.SelectedIndex == 7;
//Custom is selected
if (custom)
{
//Set the scaling
m_importData.ImportCustomScale = Double.Parse(textBoxScale.Text);
}
else
{
//Do not change the scaling
//Set unit
m_importData.ImportUnit = m_importData.EnumUnit[comboBoxUnits.SelectedIndex];
}
}
/// <summary>
/// Only numbers and '.' permitted
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBoxScale_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < (char)46 || e.KeyChar > (char)57) && (e.KeyChar != (char)8 || e.KeyChar == (char)47))
{
e.Handled = true;
}
else
{
e.Handled = false;
}
}
/// <summary>
/// Only one '.' permitted
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBoxScale_TextChanged(object sender, EventArgs e)
{
bool newPoint = false;
char tmp = '0';
string text = textBoxScale.Text.Trim();
StringBuilder textAfter = new StringBuilder();
for (int i = 0; i < text.Length; i++)
{
tmp = char.Parse(text.Substring(i, 1).ToString());
if (!newPoint && (tmp == '.'))
{
textAfter.Append(tmp);
newPoint = true;
}
else
{
if (char.IsDigit(tmp))
{
textAfter.Append(tmp);
}
}
}
textBoxScale.Text = textAfter.ToString();
}
}
}
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,196 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.ImportExport.CS
{
/// <summary>
/// Base data class which stores the basic information for import
/// </summary>
public class ImportData
{
#region Class Member Variables
/// <summary>
/// Revit command data
/// </summary>
protected ExternalCommandData m_commandData;
/// <summary>
/// Active document
/// </summary>
protected Document m_activeDoc;
/// <summary>
/// Directory where to import the file
/// </summary>
protected String m_importFolder;
/// <summary>
/// File Name or Prefix to be used
/// </summary>
protected String m_importFileFullName;
/// <summary>
/// The format to be exported
/// </summary>
protected ImportFormat m_importFormat;
/// <summary>
/// The filter which will be used in file saving dialog
/// </summary>
protected String m_filter;
/// <summary>
/// The title of importing dialog
/// </summary>
protected String m_title;
#endregion
#region Class Properties
/// <summary>
/// Revit command data
/// </summary>
public ExternalCommandData CommandData
{
get
{
return m_commandData;
}
}
/// <summary>
/// File Name or Prefix to be used
/// </summary>
public String ImportFileFullName
{
get
{
return m_importFileFullName;
}
set
{
m_importFileFullName = value;
}
}
/// <summary>
/// The format to be imported
/// </summary>
public ImportFormat ImportFormat
{
get
{
return m_importFormat;
}
set
{
m_importFormat = value;
}
}
/// <summary>
/// The filter which will be used in file saving dialog
/// </summary>
public String Filter
{
get
{
return m_filter;
}
}
/// <summary>
/// Directory where to import the file
/// </summary>
public String ImportFolder
{
get
{
return m_importFolder;
}
set
{
m_importFolder = value;
}
}
/// <summary>
/// The title of importing dialog
/// </summary>
public String Title
{
get
{
return m_title;
}
}
#endregion
#region Class Member Methods
/// <summary>
/// Constructor
/// </summary>
/// <param name="commandData">Revit command data</param>
/// <param name="importFormat">Format to import</param>
public ImportData(ExternalCommandData commandData, ImportFormat importFormat)
{
m_commandData = commandData;
m_activeDoc = commandData.Application.ActiveUIDocument.Document;
m_importFormat = importFormat;
m_filter = String.Empty;
Initialize();
}
/// <summary>
/// Initialize the variables
/// </summary>
private void Initialize()
{
//The directory into which the file will be imported
String dllFilePath = Assembly.GetExecutingAssembly().Location;
m_importFolder = Path.GetDirectoryName(dllFilePath);
m_importFileFullName = String.Empty;
}
/// <summary>
/// Collect the parameters and import
/// </summary>
/// <returns></returns>
public virtual bool Import()
{
if (m_importFileFullName == null)
{
throw new NullReferenceException();
}
return true;
}
#endregion
}
}
@@ -0,0 +1,73 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.ImportExport.CS
{
/// <summary>
/// Data class which stores the information for importing GBXML format
/// </summary>
class ImportGBXMLData : ImportData
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="commandData">Revit command data</param>
/// <param name="importFormat">Format to import</param>
public ImportGBXMLData(ExternalCommandData commandData, ImportFormat importFormat)
: base(commandData, importFormat)
{
m_filter = "XML Documents (*.xml)|*.xml";
m_title = "Import GBXML";
}
/// <summary>
/// Collect the parameters and export
/// </summary>
/// <returns></returns>
public override bool Import()
{
bool imported = false;
//parameter: GBXMLImportOptions
GBXMLImportOptions options = new GBXMLImportOptions();
//Import
Transaction t = new Transaction(m_activeDoc);
t.SetName("Import GBXML");
t.Start();
imported = m_activeDoc.Import(m_importFileFullName, options);
t.Commit();
return imported;
}
}
}
@@ -0,0 +1,100 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.ImportExport.CS
{
/// <summary>
/// Data class which stores the information for importing image format
/// </summary>
class ImportImageData : ImportData
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="commandData">Revit command data</param>
/// <param name="importFormat">Format to import</param>
public ImportImageData(ExternalCommandData commandData, ImportFormat importFormat)
: base(commandData, importFormat)
{
if (OptionalFunctionalityUtils.IsPDFImportAvailable())
m_filter = "All Image Files (*.bmp, *.gif, *.jpg, *.jpeg, *.pdf, *.png, *.tif)|*.bmp;*.gif;*.jpg;*.jpeg;*.pdf;*.png;*.tif";
else
m_filter = "All Image Files (*.bmp, *.gif, *.jpg, *.jpeg, *.png, *.tif)|*.bmp;*.gif;*.jpg;*.jpeg;*.png;*.tif";
m_title = "Import Image";
}
/// <summary>
/// Collect the parameters and export
/// </summary>
/// <returns></returns>
public override bool Import()
{
using (Transaction t = new Transaction(m_activeDoc))
{
t.SetName("Import");
t.Start();
// Step 1: Create an ImageType
//ImageTypeOptions specifies the source of the image, and how to create the ImageType.
// It can be used to specify:
// - The image file. Either as a local file path, or as an ExternalResourceRef
// - Whether to store the local file path as an absolute path or a relative path.
// - Whether to create an Import or a Link image.
// In addition, if the source is a PDF file, then ImageTypeOptions can be used to specify:
// - which page from the PDF to use
// - the resolution (in dots-per-inch) at which to rasterize the PDF
// For other image types the page number should be 1 (the default),
// and the resolution is only used to determine the size of the image.
ImageTypeOptions typeOptions = new ImageTypeOptions(m_importFileFullName, true, ImageTypeSource.Import);
ImageType imageType = ImageType.Create(m_activeDoc, typeOptions);
// Step 2: Create an ImageInstance, but only if the active view is able to contain images.
View view = CommandData.Application.ActiveUIDocument.Document.ActiveView;
if (ImageInstance.IsValidView(view))
{
// ImagePlacementOptions
ImagePlacementOptions placementOptions = new ImagePlacementOptions();
placementOptions.PlacementPoint = Autodesk.Revit.DB.BoxPlacement.TopLeft;
placementOptions.Location = new XYZ(1, 1, 1);
ImageInstance imageInstance = ImageInstance.Create(m_activeDoc, view, imageType.Id, placementOptions);
}
t.Commit();
}
return true;
}
}
}
@@ -0,0 +1,67 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.ImportExport.CS
{
/// <summary>
/// Data class which stores the information for importing image format
/// </summary>
class ImportInventorData : ImportData
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="commandData">Revit command data</param>
/// <param name="importFormat">Format to import</param>
public ImportInventorData(ExternalCommandData commandData, ImportFormat importFormat)
: base(commandData, importFormat)
{
m_filter = "Autodesk Exchange Files (*.adsk)|*.adsk";
m_title = "Import Inventor File";
}
/// <summary>
/// Collect the parameters and import
/// </summary>
/// <returns></returns>
public override bool Import()
{
//Import
Transaction t = new Transaction(m_activeDoc);
t.SetName("Import");
t.Start();
Document doc =m_commandData.Application.Application.OpenBuildingComponentDocument(m_importFileFullName);
t.Commit();
return doc == null ? false : true;
}
}
}