Author Topic: Enhanced Polyline Tutorial - Part 5 - End of the Wizard Code  (Read 1856 times)

0 Members and 1 Guest are viewing this topic.


  • Guest
Enhanced Polyline Tutorial - Part 5 - End of the Wizard Code
« on: April 12, 2009, 05:30:37 AM »
In this tutorial we’re going to begin making our custom object custom.  EPlineDxf will hold a
collection of offsets values and each offset will have a AcDbLayerId associated with it.  For the
time being we’ll limit the number of items in the collection to 5.  I’m just going to add the
member variables that need to be persisted and write the input/output code by hand.  If you
want to let the ObjectARX wizard take care of it for you can always right click on EPlineDxf and
select “Add->Add Variable”.  The wizard will give you the option of adding dwg filing code,
increasing the object version number and implementing getter/setter functions.  It works pretty
slick but might have issues with non simple data types.

COffsetProperty Class
I’ve created a new class in EPlineTutDb called COffsetProperty.  The current version of the class
only holds the offset distance and the layerId as protected members.  Public getter/setter are
defined for the variables, and it contains its own dwgOutFields and dwgInFields.  Serialization of
the class occurs during EPlineDxf’s serialization.

EPlineDxf declares a protected AcArray<COffsetProperty> collection.  Getter/setters are added
to the class as needed.  Really nothing special, look at the code.  There are a number of
methods that could be used when implementing the collection (even not using a collection). 
I’ve chosen this method because it’s simple and easy to expand in the future.  Keeping the offset
properties in its own class should help with future code maintenance.

World Draw
The worldDraw function in EPlineDxf is fleshed out completely now and probably won’t change
in future versions.  The code is pretty simple, basically when an EPlineDxf entity needs to be
drawn it checks to see if there are at least 2 vertex and that the vertex are not the same.  Then
for each COffsetProperty in the collection it creates offset geometry from the base
AcDbPolyline geometry using getOffsetCurves.  Each entity from the getOffsetCurves function
then has its layerId set to the item of COffsetProperty::LayerId and drawn.  The getOffsetCurves
is then repeated for the opposite side of the entity at the same offset distances.

A note about self intersecting entities:  If an EPlineDxf entity intersects itself on a curve then the
resulting offset curve geometry can get screwed up.  You can see the same results with the
“offset” command in AutoCAD when used on a normal polyline.  It looks like the bulge factor is
not being calculated correctly by getOffsetCurves in these instances.  Fixing the problem is
going to be outside the realm of this tutorial.

Command Line EPline
The entity creation code in rpkEPlineTutEPline has been expanded from the prior version to
include the addition of COffsetProperty items to the EPlineDxf’s collection.  The code for now is
just quick and dirty static code that’s only useful during the early stages of application
development.  The function will be replaced in the next version when a custom jig is

Command Line ConvertEPline
rpkEPlineTutConvertEPline is a new function for this version. It’s purpose is to convert an
AcDbPolyine to EPlineDxf and vise-a-versa.  Currently the conversion to EPlineDxf uses
hardcoded offset values.  When the UI is developed in a future version these functions will be
replaced as well.

Testing it Out
As usual compile EPlineTutDb then EPlineTut and load the binaries (same order) in AutoCAD.
Draw a normal LWPolyline with multiple segments, straight, curved, etc.  When done type
ConvertEPline at the AutoCAD command line and select the polyline you drew.  The polyline is
converted with offsets 5, 10, 15 units apart.  Select the polyline and modify it using the
vertex grips.  Intersections are automatically cleaned up (see World Draw section above
about limits to geometry clean up).  Run ConvertEPline again and select the EPlineDxf entity,
it's converted back to a normal LWPolyline.

You'll notice that the offset segments take on layer 0.  When we develop the UI for the program
these will be made user selectable along with the offset distances.

A small amount of code (relative terms) was added for this tutorial, most should be self
explanitory.  With the addition of a custom jig in the next tutorial, followed by a UI I think it’s
close to being done.

One feature I’d like to possibly add is tangency constraints at vertex points when dragging and
drawing the enity.  This will be strickly be based on being able to fit it within commitments I’ve
already got going on.