Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selecting Profile by its Name

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Anonymous
620 Views, 9 Replies

Selecting Profile by its Name

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

 

 

9 REPLIES 9
Message 2 of 10
Jeff_M
in reply to: Anonymous

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

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 10
Anonymous
in reply to: Jeff_M

Thanks it worked

 

Tamer

Message 4 of 10
brianchapmandesign
in reply to: Anonymous

Is this possible through lisp?


"Very funny, Scotty. Now beam down my clothes.
Message 5 of 10
Jeff_M
in reply to: brianchapmandesign

Yes. Using the ActiveX(Com) API.

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 10
brianchapmandesign
in reply to: Jeff_M

Roger that Jeff... will give it a shot... 


"Very funny, Scotty. Now beam down my clothes.
Message 7 of 10
Jeff_M
in reply to: brianchapmandesign

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
    )
  )

 

Jeff_M, also a frequent Swamper
EESignature
Message 8 of 10
Jeff_M
in reply to: Jeff_M

I have no idea why that code split into 2 code panes. I only used one.

Jeff_M, also a frequent Swamper
EESignature
Message 9 of 10
brianchapmandesign
in reply to: Jeff_M

(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????


"Very funny, Scotty. Now beam down my clothes.
Message 10 of 10
brianchapmandesign
in reply to: Jeff_M

Hey Jeff...

 

Would you mind showing this example in c#?


"Very funny, Scotty. Now beam down my clothes.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report