why this dynamo code not working for autocad?

why this dynamo code not working for autocad?

thsa2501
Enthusiast Enthusiast
679 Views
5 Replies
Message 1 of 6

why this dynamo code not working for autocad?

thsa2501
Enthusiast
Enthusiast

hii everyone,

 

i try to sort numbers for attribute blocks via polyline vertex but it does not work.

this code is from one of the youtube channel his name "Khasan Mamaev".

i attached dynamo code and drawing.

if not understand what am i trying to say, kindly watch https://youtu.be/K5pjPOcFl6A.

thanks, advance

best regards 

hussain

 

 

 

 

 

 

it popup message it has no attribute for active documentit popup message it has no attribute for active document

0 Likes
680 Views
5 Replies
Replies (5)
Message 2 of 6

hosneyalaa
Advisor
Advisor

hi

try

 

# Blocks numerator
# ©2017, Khasan Mamaev
# www.dynamobim.ru


if IN[0] != True: off = 1/0
tagARK = IN[1]


scale = float(IN[2])
r = 250.0 * scale/100

rev = IN[3]

import clr
from operator import itemgetter
import re
import System

clr.AddReference('ProtoGeometry')
import Autodesk
from Autodesk.DesignScript.Geometry import *
DPoint = Autodesk.DesignScript.Geometry.Point

app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application")
AcDoc = app.ActiveDocument
AcDoc.SendCommand("(SSGET\"_x\"'((-4 . \"<OR\")(0 . \"*TEXT,*Polyline\")(-4 . \"<AND\")(0 . \"INSERT\")(66 . 1)(-4 . \"AND>\")(-4 . \"OR>\"))) ")
AcDoc.SendCommand("SELECT (SSGET\"_p\")  ")
sset = AcDoc.PickfirstSelectionSet


def ptD(p):
	return DPoint.ByCoordinates(p[0],p[1],p[2])

def vertex(pl):
	pts = []
	for i,k in enumerate(pl):
		if i%2 == 0:
			pts.append(DPoint.ByCoordinates(k, pl[i+1], 0.0))
	return pts

def cir(p,r):
	return Circle.ByCenterPointRadius(p,r)

blocks = []
circs = []
RRR = []
for j in sset:
    
	if j.ObjectName == 'AcDbPolyline':
		poly = j
		#RRR.append(j)
	elif j.ObjectName == 'AcDbBlockReference':
		attr = j.GetAttributes()
		#RRR.append(j)
		for i in attr:
		    #RRR.append( i.TagString )
		    if i.TagString != tagARK:
		       p = ptD(j.InsertionPoint)
		       blocks.append([j, cir(p,r)])
		       circs.append(cir(p,r))
		    elif i.TagString == tagARK:
		         arknum = re.sub("\D", "", i.TextString)
		         RRR.append( arknum )
		         ark = i
		       
acPoints = poly.Coordinates		       
pline = PolyCurve.ByPoints(vertex(acPoints))




OUT = pline

 

 

Capture9.JPG

 

0 Likes
Message 3 of 6

thsa2501
Enthusiast
Enthusiast

hi

thanks for the message.it does not work for me.i attached image the message popup when i trying to run.kindly solve me.i am using autocad 2024 and dynamo sandbox.

kinldy make a video to understand this.

0 Likes
Message 4 of 6

hosneyalaa
Advisor
Advisor

I think the error is because

Opening two Autocad files

It is preferable to use dynamo through civil 3 d If possible you have There are options Easier, better and faster

Or in this method you must have knowledge of using Object Model (ActiveX)

 

Screenshot_٢٠٢٣_٠٧٢٨_٢٣١٥٢٢.jpg

0 Likes
Message 5 of 6

thsa2501
Enthusiast
Enthusiast

hi,

ok i will try to using civil 3d,but i would like to know. how it works dynamo only in autocad for him.

0 Likes
Message 6 of 6

hosneyalaa
Advisor
Advisor

TRY

@thsa2501 

 

# Blocks numerator
# ©2017, Khasan Mamaev
# www.dynamobim.ru


import clr
from operator import itemgetter
import re
import System

clr.AddReference('ProtoGeometry')
import Autodesk
from Autodesk.DesignScript.Geometry import *
DPoint = Autodesk.DesignScript.Geometry.Point

app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application")
AcDoc = app.ActiveDocument
AcDoc.SendCommand("(SSGET\"_x\"'((-4 . \"<OR\")(0 . \"*TEXT,*Polyline\")(-4 . \"<AND\")(0 . \"INSERT\")(66 . 1)(-4 . \"AND>\")(-4 . \"OR>\"))) ")
AcDoc.SendCommand("SELECT (SSGET\"_p\")  ")
sset = AcDoc.PickfirstSelectionSet


def ptD(p):
	return DPoint.ByCoordinates(p[0],p[1],p[2])

def vertex(pl):
	pts = []
	for i,k in enumerate(pl):
		if i%2 == 0:
			pts.append(DPoint.ByCoordinates(k, pl[i+1], 0.0))
	return pts

def cir(p,r):
	return Circle.ByCenterPointRadius(p,r)

blocks = []
circs = []
RRR = []
for j in sset:
    
	if j.ObjectName == 'AcDbPolyline':
		poly = j
		#RRR.append(j)
		       
acPoints = poly.Coordinates		       





OUT = acPoints

 

 

# Blocks numerator
# ©2017, Khasan Mamaev
# www.dynamobim.ru



import clr
from operator import itemgetter
import re
import System

clr.AddReference('ProtoGeometry')
import Autodesk
from Autodesk.DesignScript.Geometry import *
DPoint = Autodesk.DesignScript.Geometry.Point

app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application")
AcDoc = app.ActiveDocument
AcDoc.SendCommand("(SSGET\"_x\"'((-4 . \"<OR\")(0 . \"*TEXT,*Polyline\")(-4 . \"<AND\")(0 . \"INSERT\")(66 . 1)(-4 . \"AND>\")(-4 . \"OR>\"))) ")
AcDoc.SendCommand("SELECT (SSGET\"_p\")  ")
sset = AcDoc.PickfirstSelectionSet

tagARK = IN[0]
blocks = []
circs = []
RRR = []
for j in sset:
    
	if j.ObjectName == 'AcDbPolyline':
		poly = j
		#RRR.append(j)
	elif j.ObjectName == 'AcDbBlockReference':
		attr = j.GetAttributes()
		#RRR.append(j)
		for i in attr:
		    #RRR.append( i.TagString )
		    if i.TagString != tagARK:
		       p = ptD(j.InsertionPoint)
		       blocks.append([j, cir(p,r)])
		       circs.append(cir(p,r))
		    elif i.TagString == tagARK:
		         arknum = re.sub("\D", "", i.TextString)
		         RRR.append( arknum )
		         ark = i
		       





OUT = RRR

 

 

Capture10.JPG

0 Likes