I am writing a code using VB.net and i am trying to select the profile using its name and i am always having an exception error
Dim
ed AsEditor = Application.DocumentManager.MdiActiveDocument.Editor()
Dim mydoc AsDocument = Application.DocumentManager.MdiActiveDocument
Dim mydb AsDatabase= mydoc.Database
Dim mytrans AsTransaction = mydb.TransactionManager.StartTransaction
Dim mycivil As CivilDocument= Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument
Try
Dim opt AsPromptEntityOptions = NewPromptEntityOptions("Select an Alignment")
opt.SetRejectMessage(
"Object Must be an Alignment")
opt.AddAllowedClass(
GetType(Alignment), False)
Dim a1 AsObjectId= ed.GetEntity(opt).ObjectId
Dim a2 AsAlignment = mytrans.GetObject(a1, OpenMode.ForRead)
Dim profname as string=inputbox ("Please Enter Profile Name")
dim p1 as profile=mytran.getobject(a2.getprofileids(profname),openmode.forread)
Thanks,
Tamer Mourad
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
The GetProfileIds() method returns ObjectIds, so has no knowledge of the name associated with them. Lope through the the ObjectsIds, using GetObject() with each one, check the name, exit when te correct one is found.
I don't normally use VB but this should be close:
dim p1 as profile
foreach id As ObjectId in a2.getprofileids()
p1 = mytran.GetObject(id, OpenMode.ForRead)
if p1.name = profname
exit for
next
Is this possible through lisp?
Roger that Jeff... will give it a shot...
I'm feeling a bit lispy so here's a good start for you.....
(vl-load-com) (setq prod (vlax-product-key)) (setq verstr (cond ((vl-string-search "\\R18.0\\" prod) "7.0" ) ;;2010 ((vl-string-search "\\R18.1\\" prod) "8.0" ) ;;2011 ((vl-string-search "\\R18.2\\" prod) "9.0" ) ;;2012 ) ) (setq prodStr (strcat "AeccXUiLand.AeccApplication." verstr))
;;set the names to find, these are both in a test file I have (setq alignname "Chanate Road" profname "CL-FG") (if (and (setq *acad* (vlax-get-acad-object)) (setq C3D (vla-getinterfaceobject *acad* prodStr)) (setq C3Ddoc (vla-get-activedocument C3D)) ) (progn (setq aligns (vlax-get c3ddoc 'alignmentssiteless)) (setq align (vlax-invoke aligns 'item alignname)) (setq profiles (vlax-get align 'profiles)) (setq prof (vlax-invoke profiles 'item profname)) ;;do what you want with the profile ) )
(setq profiles (vlax-get-property obj 'profiles))
followed by
(setq obj2 (vlax-invoke-method obj2 'item "CL-FG"))
obj being alignment
I think i need to append the alignment name to the front of "CL-FG" and assign my FG profiles names accordingly to keep this automated and correct, but not sure how to append it. Any thoughts. would (strcat alignment "CL-FG" work)... i wonder????
Hey Jeff...
Would you mind showing this example in c#?