Applying Field to Multiple Objects

Applying Field to Multiple Objects

paulmcclafferty4
Explorer Explorer
5,473 次查看
10 条回复
1 条消息(共 11 条)

Applying Field to Multiple Objects

paulmcclafferty4
Explorer
Explorer

Hello,

 

I need to use the FIELD function to extract attributes from multiple objects at once.

 

The "roadnamela" is the attribute I need.

 

There are 4 roads in the attached drawing sample, however my aim is to name hundreds of roads using this method if I can complete this action at once.

 

Thanks in advance for the help.

0 个赞
已接受的解答 (1)
5,474 次查看
10 条回复
回复 (10)
2 条消息(共 11 条)

imadHabash
Mentor
Mentor

Hi,

>> I need to use the FIELD function to extract attributes from multiple objects at once.

to extract attributes in AutoCAD you can use DATAEXTRACTION command . >> Click << 

 

Imad Habash

EESignature

0 个赞
3 条消息(共 11 条)

serkancavuslar
Collaborator
Collaborator
已接受的解答

@paulmcclafferty4 @imadHabash 

 

Attribute Block Multiple Select and mText 🙂

 

Serkan ÇAVUŞLAR

CplCAD İstanbul / Türkiye

 

	(defun c:attmt(/ aDoc aSp oSiz bSet aLst cLst tStr nTxt bCtr Tags TextInsert)
		(setq Tags nil)
		(setq TextInsert T)
		
		(defun GetBoundingCenter (vlaObj / blPt trPt cnPt)
			(vla-GetBoundingBox vlaObj 'minPt 'maxPt)
			(setq	blPt (vlax-safearray->list minPt)
					trPt (vlax-safearray->list maxPt)
					cnPt (vlax-3D-point (list (+ (car blPt) (/ (- (car trPt)(car blPt)) 2.0)) (+ (cadr blPt) (/ (- (cadr trPt)(cadr blPt))2.0)) 0.0))
			)
		)
		
		(if (not Size) (setq Size(getvar "TEXTSIZE")))
		(setq  oSiz Size
			   Size (getreal (strcat "\nText size <"(rtos Size)">: "))
		)
		(if (null Size)(setq Size oSiz))
		(setq aDoc (vla-get-ActiveDocument(vlax-get-acad-object)))
		
		(if (= 1 (vla-get-ActiveSpace aDoc))
			(setq aSp (vla-get-ModelSpace aDoc))
			(setq aSp (vla-get-PaperSpace aDoc))
		)
		
		(if (setq bSet (ssget '((0 . "INSERT"))))
			(progn
				(foreach b (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex bSet))))
					(setq	aLst '()
							tStr ""
					)
					(if TextInsert
						(setq bCtr(GetBoundingCenter b))
						(setq bCtr(vla-get-InsertionPoint b))
					)
					(if ;(and 
							(= :vlax-true (vla-get-HasAttributes b))
						;	(safearray-value
						;		(setq atts (vlax-variant-value (vla-getattributes b)))
						;	)
						;	(foreach tag (vlax-safearray->list atts)
						;		(= (vla-get-tagstring tag) "roadnamela")
						;	)
						;)
						(progn
							(setq aLst (mapcar '(lambda (a) 
								(if (= (vla-get-TagString a) "roadnamela")
									(list (vla-get-TagString a) (vla-get-TextString a))
									(list "" "")
								)
								
								) (vlax-safearray->list (vlax-variant-value (vla-GetAttributes b)))))
							(foreach i (reverse aLst)
								(setq tStr (strcat tStr (if Tags (strcat (car i) ": ") "") (last i) "\\P"))
							)
							(if (/= "" tStr)
								(progn
									(setq nTxt (vla-AddMText aSp bCtr (* Size 30.0) tStr))
									(vla-put-Height nTxt Size)
								)
							)
						)
					)
				)
				(vla-EndUndoMark aDoc)
			)
		)
	 (princ)
	)

 

Serkan ÇAVUŞLAR
CplCAD / Türkiye
4 条消息(共 11 条)

paulmcclafferty4
Explorer
Explorer

Thank you very much! you have saved me a LOT of time! 

5 条消息(共 11 条)

Anonymous
不适用

I don't understand, is this a script I need to run? 

0 个赞
6 条消息(共 11 条)

Michiel.Valcke
Advisor
Advisor

This is autolisp code, you save the code as a text file with the extension .lsp (you can also download it from @serkancavuslar 's post.)

You can add the code to your AutoCad with the command _APPLOAD

Once you have done so you can call the command from the command bar (in this case the command is ATTMT - you can always recognize it because it is prefaced with the code: " defun c: " )

0 个赞
7 条消息(共 11 条)

aponsBA4NG
Contributor
Contributor

hello!

I would like to know if it would be possible to do the same with the properties of hathces
I have tested the lsp with hatches and it does not recognize them as objects

 

thanks in advance for your time!

 

0 个赞
8 条消息(共 11 条)

joelTFPVU
Community Visitor
Community Visitor

I want to use this script to assign text showing the elevation location of each point. what would 
I have to change in that script to make it work?

0 个赞
9 条消息(共 11 条)

joelTFPVU
Community Visitor
Community Visitor

For example, I can link a text displaying the field value of Position Z for each point. But If I have 238 elevation points I don't want to manually do each one. Can a similar script be ran for this.

 

Thanks!

0 个赞
10 条消息(共 11 条)

Michiel.Valcke
Advisor
Advisor
If you have an AutoCAD full version (not LT) then you should also have access to the AutoCAD MAP 3D toolset (you have to install it as a separate software, but it is included in the same license) you can add text labeling for such things directly with AutoCAD MAP 3D workflows, no need to use fields.
0 个赞
11 条消息(共 11 条)

joelTFPVU
Community Visitor
Community Visitor

Thanks, yeah I do have the full version. I just downloaded the AutoCad Map 3D.

I will play around with that,  see if I can figure it out.

 

Thanks

0 个赞