.NET

Reply
Contributor
sivaulagu
Posts: 11
Registered: ‎01-19-2012
Message 1 of 3 (427 Views)
Accepted Solution

acadentity in vb and Vb.net

427 Views, 2 Replies
01-19-2012 01:07 AM

previously i was using vb6 to automate drawings in autocad,

but now i've switched to vb.net and i'm facing lot many problem wen i use option strict and explicit to ON.

i've used

dim cadEnt as acdentity

i can get

cadEnt.startpoint

cadEnt.objectname

cadEnt.coordinates

in vb6 startpoint was variant datatype

 

 

but in vb.net i couldnt get

cadEnt.startpoint

cadEnt.coordinates

wat is it in Vb.net

Hi,

 

as long as you use Option Strict (without any exceptions) late-binding would be disallowed. Look at this screenshot, if you set STRICT to ON ==> latebinding will raise an error.

 

And one more word to that: set the option as global for you project within the project-properties and not within the code-file(s).

 

Having set that you would not get compiled your code

dim cadEnt as acdentity

i can get

cadEnt.startpoint

Because the object of type "AcadEntity" does not have a property called "StartPoint" (as AcadEntity can reference any geometry-objects, something like AcadCircle or AcadHatch or ....)

 

If you have a line and want to get it's startpoint you have to use a variable of type AcadLine

If you have a polyline and want to have it's vertices you have to check what type of polyline it is (LWPoly, 2D-Poly, 3D-Poly) and have to use this type to declare the variable.

 

Of course ... you can remove now option strict and all will be as you mentioned "I have a object from any type, give me the start point" ==> but as long as this object does not have a start point the code will crash.

Even if you have a perfect error handling the crash uses a lot of time, so a lot of performance.

 

The big disadvantage of having option strict on is that you have to write more code.

The big advantage of having option strict on is your code won't crash because it would even not get compiled. So you see possible problems within your code just while writing it, not if a user selects the wrong object type and then AutoCAD is away with some greetings like "unhandled exception" at the customer.

 

HTH, - alfred -

 

*Expert Elite*
Alfred.NESWADBA
Posts: 9,598
Registered: ‎06-29-2007
Message 2 of 3 (422 Views)

Re: acadentity in vb and Vb.net

01-19-2012 01:48 AM in reply to: sivaulagu

Hi,

 

as long as you use Option Strict (without any exceptions) late-binding would be disallowed. Look at this screenshot, if you set STRICT to ON ==> latebinding will raise an error.

 

And one more word to that: set the option as global for you project within the project-properties and not within the code-file(s).

 

Having set that you would not get compiled your code

dim cadEnt as acdentity

i can get

cadEnt.startpoint

Because the object of type "AcadEntity" does not have a property called "StartPoint" (as AcadEntity can reference any geometry-objects, something like AcadCircle or AcadHatch or ....)

 

If you have a line and want to get it's startpoint you have to use a variable of type AcadLine

If you have a polyline and want to have it's vertices you have to check what type of polyline it is (LWPoly, 2D-Poly, 3D-Poly) and have to use this type to declare the variable.

 

Of course ... you can remove now option strict and all will be as you mentioned "I have a object from any type, give me the start point" ==> but as long as this object does not have a start point the code will crash.

Even if you have a perfect error handling the crash uses a lot of time, so a lot of performance.

 

The big disadvantage of having option strict on is that you have to write more code.

The big advantage of having option strict on is your code won't crash because it would even not get compiled. So you see possible problems within your code just while writing it, not if a user selects the wrong object type and then AutoCAD is away with some greetings like "unhandled exception" at the customer.

 

HTH, - alfred -

 

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
sivaulagu
Posts: 11
Registered: ‎01-19-2012
Message 3 of 3 (413 Views)

Re: acadentity in vb and Vb.net

01-19-2012 02:16 AM in reply to: Alfred.NESWADBA

s i want to keep option strict on....

tats my boss order...

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.