Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

chuongmep/CadPythonShell

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CADPythonShell

Autocad API Platform License: MIT follow on Twitter

ReSharper Rider Visual Studio 2022 .NET Framework

Publish

Introduction

This is obviously a fork of RevitPythonShell, bringing an IronPython interpreter to Autodesk Autocad, and it would not be possible without the great work of everyone involved with the RPS project. It's still pretty rough around the edges and provides only basic functionality at this time. I'm sharing my work so far, in the hopes that together we can expand it further.

The CADPythonShell (CPS) ,lets you to write plugins for Autocad in Python, provides you with an interactive shell that lets you see the results of your code as you type it. This is great for exploring the Autocad API.

The biggest limitation is that you can't deploy DLLs with custom scripts at this time and you can't subscribe to events at startup time.

Features

  • Interactive IronPython interpreter for exploring the API
    • With syntax highlighting and autocompletion (in the console only)
    • Based on the IronLab project
  • Batteries included! (Python standard library is bundled as a resource in the CADRuntime.dll)
  • Full access to the .NET framework and the Autocad and Civil3D API
  • Configurable "environment" variables that can be used in your scripts
  • Save "external scripts" for reuse and start collecting your awesome hacks!
  • Run scripts at Autocad or Civil startup

Installation

  • Download last install stable(msi) from Release
  • Use command PythonConsole to open Console or use command PythonShellSetting to open form setting
  • See guide install detail at How-to-Install-CadPythonShell

Note : Support for 4 last version(2019-2022) Autocad or Civil 3D. Older versions can be used but will not guarantee the expected performance.

Basic Usage

  • PythonConsole - Open Python Console
  • PythonShellSetting - Open Setting Config Console
  • Snoop - Snoop Object In CAd or Civil3d

  • Write Console Sample
ed = doc.Editor
ed.WriteMessage("Hello")

  • Try create script get Object
import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import os
import math
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')
# 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 *
adoc = Application.DocumentManager.MdiActiveDocument
ed = adoc.Editor
with adoc.LockDocument():
	with adoc.Database as db:
		with db.TransactionManager.StartTransaction() as t:
  			bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
  			btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
  			for objectid in btr:
				obj1 = t.GetObject(objectid, OpenMode.ForRead)
				print(obj1)
ed.WriteMessage("Done")

Note : you can see more example in folder Script Examples

Contribute

  • Don't hesitate to file any issues you stumble uppon. (Tho I don't guarantee I'll be able to solve them all for you)

Getting started:

Learn some python:

Learn about the Autocad API:

License

This project is licensed under the terms of the MIT License.

Sponsors

Thanks to JetBrains for providing licenses for Rider and dotUltimate tools, which both make open-source development a real pleasure!

Credits

  • Daren Thomas (original RPS Developer) RPS
  • Joe Moorhouse (interactive shell was taken from his project IronLab)
  • Dimitar Venkov (original port to Navisworks)
  • ChuongMep (original port to Autocad)
  • The rest of the RPS contributors
  • Nice 3 Point for process CI/CD
  • Icon 8 Free Wiki icons in various UI design styles for web, mobile
  • htlcnn origin of project AutocadLookup
Morty Proxy This is a proxified and sanitized view of the page, visit original site.