TheSwamp

Code Red => .NET => Topic started by: David Hall on May 20, 2010, 03:18:43 PM

Title: reinvent the wheel
Post by: David Hall on May 20, 2010, 03:18:43 PM
A couple of thought provoking questions.  OK, so maybe I should give you some background first.  For those of you that dont know, I work for an Electric Utility.  Our typical construction prints consist for 4 basic types of drawings:
Now I have evaluated Autocad Electrical over the last 2 weeks, and while it is very cool, and automates a ton of work, it was designed more for panel manufactures than a utility.  There is so much front end work to pick out every part, manf., blah blah blah. that using it requires too much work.  Our substation and Relay crews install terminal blocks, and then wire them up.

Also, when I was evaluating Electrical, I was highly disappointed in that when AE inserts a contact or device, its just a stupid block, not even dynamic.  Also, instead of using some wisbang magic, it cuts/trims/breaks the line you inserted it upon.  Should you move the block, it doesn't fix the line.  Now there might be some AutoMagic in there somewhere that will fix the line, but I didn't find it yet.

So my question for you gurus is this: (and bear in mind I haven't done much research yet) should I reinvent the wheel in .Net to insert blocks and trim the lines or do it the old out of the box way?  I am all for making it uber easy with customization, but how hard might it be if the TRIM or BREAK methods aren't exposed to .Net.
Title: Re: reinvent the wheel
Post by: LE3 on May 20, 2010, 03:31:02 PM
I have used in the past getSplitCurves or GetSplitCurves from C# - that you can use to break or trim any Curve object - maybe?
Title: Re: reinvent the wheel
Post by: T.Willey on May 20, 2010, 03:50:36 PM
FYI... You can use the ' Move Component ' command from the ' Components ' pull down, or type ' aemove ' at the command line.  It will move the component, remove the break, then break the line you move it to.  Only thing is, that the command only lets you select a single component.

If you want to move more, then I would use the ' Copy Circuit ' from the ' Componets ' pull down, then use the ' Delete Components ' command.  Not the best, but a work-around.
Title: Re: reinvent the wheel
Post by: mohnston on May 20, 2010, 03:58:06 PM
Out-of-the-box customization products (Adesk verticals) are good and bad.
Good: They have a team of programmers behind them and they are usually quality products.
Bad: They tend to do what *some* people thought *most* people want. And they try to please a wide variety of customers which means a lot of effort has to go into accommodating a wide variety of methods of working.
 
The beauty of doing it yourself is that you can make it do what YOU want. This is especially valuable when you go to tie in your design data with your company systems.


P.S. - Did I just see "Kenny Ramage" as the Latest Member? *blink* *blink*
Title: Re: reinvent the wheel
Post by: dgorsman on May 20, 2010, 04:02:26 PM
Just keeping track - a good part of our work is P&IDs (and some electrical drawings as well) which is pretty similar, I think. 

We use in-house stuff for the electrical drawings, as the department boss wants to keep things cheap and simple, no license costs, handles AutoCAD upgrades much better, etc.  Sounds like you might be better off rolling your own as well.  After a certain point the product requires so much customization to work "properly" you might as well.  Just keep in mind that others may have to work with your drawings, so not too wild and crazy.  Then again, I haven't even looked at Electrical so....  :angel:

Rather than trim or break, I just erase the original and redraw two lines instead (in LISP, no less).  I'm considering dumping some XRECORD data into the inserted object to reference the connected line handles so they can be relocated if the inserted object is moved.
Title: Re: reinvent the wheel
Post by: David Hall on May 20, 2010, 04:29:07 PM
...Rather than trim or break, I just erase the original and redraw two lines instead ...
This was one of my thoughts as well, especially since it is very easy to do in .Net.  I just didn't want to throw out my ideas til everyone else joined the party
Title: Re: reinvent the wheel
Post by: David Hall on May 20, 2010, 04:30:35 PM
I have used in the past getSplitCurves or GetSplitCurves from C# - that you can use to break or trim any Curve object - maybe?
Good to know, thanks Luis
Title: Re: reinvent the wheel
Post by: uncoolperson on May 20, 2010, 07:12:48 PM
use the autocad electrical move component command.

My old department uses electrical for schematics, though none of the interface for electrical remained the same took a few hundred hours of rewriting things (in lisp) to work how I want them to.

the reports are nifty, not sure if it's worth the costs, but if you get in to it you can get it to do what you want (or atleast for what we wanted).... even when the reseller and instructor both said "it can't be done" (ha!).
Title: Re: reinvent the wheel
Post by: Bryco on May 21, 2010, 09:45:00 AM
Perhaps this could be a good use of the new 2d parametric stuff. Tie the line to a point on the block. I have no idea if this is exposed in net.
Title: Re: reinvent the wheel
Post by: David Hall on May 21, 2010, 11:03:02 AM
I never thought of that, that could be very cool.  I haven't installed 11 yet, but I will have to look into that.
Title: Re: reinvent the wheel
Post by: David Hall on May 21, 2010, 04:49:07 PM
Preliminary testing done, I'm liking the read a Line, erase and draw 2 new lines with a gap between them.  Kudos to Kerry for the GetPointbyVector (http://www.theswamp.org/index.php?topic=20656.msg251048#msg251048) function.  Next, I am trying to decide how/where to store the data behind the scenes for the connections.  I'm open to suggestions.  So far I'm thinking XRECORDS or Dictionaries.  I know nothing about either, so please let me know which would be better.  I can provide a dwg file if that would help explain what Im thinking (assuming that would make 1 better than the other)
Title: Re: reinvent the wheel
Post by: dgorsman on May 21, 2010, 06:23:22 PM
You need dictionaries to store XRECORDS so I say both.   :wink:

My preference is for creating an application-specific dictionary under the inserted objects extension dictionary, with XRECORDS as necessary to track information e.g. soft pointer handles.  You could also put them into a drawing dictionary but that creates a couple of extra steps for getting the information.  I find XRECORDS and dictionaries a little easier to deal with than XDATA, but thats another option.

You will probably want to add a pointer back to the inserted object to the two new lines (and copy the existing ones from the erased line) so you can get back to the inserted object by line.  Add a pointer to each new line to the inserted object, and using either monitoring command use or creating your own commands you can adjust both connecting lines and inserted objects as needed.
Title: Re: reinvent the wheel
Post by: It's Alive! on May 21, 2010, 08:49:32 PM
 Should you move the block, it doesn't fix the line.

what about a persistent reactor?
Title: Re: reinvent the wheel
Post by: David Hall on May 22, 2010, 10:03:50 AM
You need dictionaries to store XRECORDS so I say both.   :wink:
I told you I know nothing about what I speak
My preference is for creating an application-specific dictionary under the inserted objects extension dictionary, with XRECORDS as necessary to track information
e.g. soft pointer handles.  You could also put them into a drawing dictionary but that creates a couple of extra steps for getting the information.
Do you have a small example of this?
....or creating your own commands you can adjust both connecting lines and inserted objects as needed.
Exactly what I was thinking
Title: Re: reinvent the wheel
Post by: sinc on May 22, 2010, 10:25:24 AM
You may want to take a look at this for a sample of how to use soft pointer ids:

http://through-the-interface.typepad.com/through_the_interface/2006/11/linking_circles_1.html
Title: Re: reinvent the wheel
Post by: David Hall on May 22, 2010, 10:48:09 AM
WOW! I am so in over my head....
Title: Re: reinvent the wheel
Post by: jgr on May 22, 2010, 10:55:34 PM
I do not speak English, and maybe did not understand the question. But:

(electrical schematic/wiring ) For breack lines you can use (Entity) points on blocks (see http://patrice.delseaux.free.fr/ , is lisp, but to get an idea is good) or store this break points in a database .
Title: Re: reinvent the wheel
Post by: David Hall on May 25, 2010, 07:20:37 PM
OK, after reading much of that, I'm seeing DXF codes being used.  Is this correct or is there another list I should be looking at?
Title: Re: reinvent the wheel
Post by: David Hall on May 27, 2010, 03:37:18 PM
I have been playing around with this for a few days, and found that it looks like I can use any number I want.  Is there a standard for which DXF codes should be used in XRecords?
Title: Re: reinvent the wheel
Post by: T.Willey on May 27, 2010, 04:03:38 PM
I have been playing around with this for a few days, and found that it looks like I can use any number I want.  Is there a standard for which DXF codes should be used in XRecords?

For what numbers to use, look in the Dev Help, look at the ' DXF Reference ' section.  Then ' DXF Format ', then ' Group Code Value Types ' or ' Group Codes in Numerical Order '.  Here is a quote from the former.

Quote
Code range
 Group value type
 
0-9
 String (with the introduction of extended symbol names in AutoCAD 2000, the 255-character limit has been increased to 2049 single-byte characters not including the newline at the end of the line)
 
10-39
 Double precision 3D point value
 
40-59
 Double-precision floating-point value
 
60-79
 16-bit integer value
 
90-99
 32-bit integer value
 
100
 String (255-character maximum; less for Unicode strings)
 
102
 String (255-character maximum; less for Unicode strings)
 
105
 String representing hexadecimal (hex) handle value
 
110-119
 Double precision floating-point value
 
120-129
 Double precision floating-point value
 
130-139
 Double precision floating-point value
 
140-149
 Double precision scalar floating-point value
 
170-179
 16-bit integer value
 
210-239
 Double-precision floating-point value
 
270-279
 16-bit integer value
 
280-289
 16-bit integer value
 
290-299
 Boolean flag value
 
300-309
 Arbitrary text string
 
310-319
 String representing hex value of binary chunk
 
320-329
 String representing hex handle value
 
330-369
 String representing hex object IDs
 
370-379
 16-bit integer value
 
380-389
 16-bit integer value
 
390-399
 String representing hex handle value
 
400-409
 16-bit integer value
 
410-419
 String
 
420-429
 32-bit integer value
 
430-439
 String
 
440-449
 32-bit integer value
 
450-459
 Long
 
460-469
 Double-precision floating-point value
 
470-479
 String
 
999
 Comment (string)
 
1000-1009
 String (same limits as indicated with 0-9 code range)
 
1010-1059
 Double-precision floating-point value
 
1060-1070
 16-bit integer value
 
1071
 32-bit integer value
 

For Xrec specific, then look at: DXF Reference -> Objects Section -> Xrecords.  Here is the quote from there.

Quote
The following group codes are common to all xrecord objects. In addition to the group codes described here, see Common Group Codes for Objects. For information about abbreviations and formatting used in this table, see Formatting Conventions in This Reference.

Xrecord group codes
 
Group code
 Description
 
100
 Subclass marker (AcDbXrecord)
 
280
 Duplicate record cloning flag (determines how to merge duplicate entries):

0 = Not applicable

1 = Keep existing

2 = Use clone

3 = <xref>$0$<name>

4 = $0$<name>

5 = Unmangle name
 
1-369 (except 5 and 105)
 These values can be used by an application in any way
 

Xrecord objects are used to store and manage arbitrary data. They are composed of DXF group codes with “normal object” groups (that is, non-xdata group codes), ranging from 1 through 369 for supported ranges. This object is similar in concept to xdata but is not limited by size or order.

Xrecord objects are designed to work in such a way as to not offend releases R13c0 through R13c3. However, if read into a pre-R13c4 version of AutoCAD®, xrecord objects disappear.
Title: Re: reinvent the wheel
Post by: David Hall on May 27, 2010, 04:41:17 PM
Thanks Tim.  I read that on the net, but when I read the part about R13c0-3, I thought it must be very old information, and kept looking for newer information.  BTW, do you have a short example of storing some data in an XRECORD?  I have used a few examples I have found, but they are very generic
Title: Re: reinvent the wheel
Post by: T.Willey on May 27, 2010, 05:52:14 PM
Here is something simple.  Hope it helps.
Code: [Select]
public bool SaveXrefState ( Database db, DBDictionary dict, string name )
{
    Xrecord Xrec = new Xrecord();
    ResultBuffer rb = new ResultBuffer();
    using ( Transaction Trans = db.TransactionManager.StartTransaction() )
    {
        db.ResolveXrefs( false, true );
        XrefGraph xrGph = db.GetHostDwgXrefGraph( false );
        for ( int i = 1; i < xrGph.NumNodes; i++ )
        {
            XrefGraphNode xrNode = xrGph.GetXrefNode( i );
            BlockTableRecord btr = Trans.GetObject( xrNode.BlockTableRecordId, OpenMode.ForRead ) as BlockTableRecord;
            if ( btr == null ) continue;
            rb.Add( new TypedValue( 5, btr.Handle ) );
            rb.Add( new TypedValue( 62, ( btr.XrefStatus == XrefStatus.Unloaded ? 1 : 0 ) ) );
        }
        Xrec.Data = rb;
        if ( !dict.IsWriteEnabled ) dict.UpgradeOpen();
        dict.SetAt( name, Xrec );
        dict.DowngradeOpen();
        Trans.Commit();
    }
    return true;
}
Title: Re: reinvent the wheel
Post by: David Hall on May 27, 2010, 06:00:18 PM
every thing helps!  The more examples I see the better
Title: Re: reinvent the wheel
Post by: David Hall on May 27, 2010, 06:34:28 PM
OH, Its making so much sense now!!!  The wheels are starting to turn much quicker now.
Title: Re: reinvent the wheel
Post by: T.Willey on May 27, 2010, 06:47:13 PM
That's always a good thing.
Title: Re: reinvent the wheel
Post by: Kerry on May 27, 2010, 07:53:08 PM
OH, Its making so much sense now!!!  The wheels are starting to turn much quicker now.

copious amounts of bourbon help lubrication David.
Title: Re: reinvent the wheel
Post by: David Hall on May 28, 2010, 09:31:02 AM
copious amounts of bourbon help lubrication David.
Funny you should say that, I had a good long chat with a mutual friend about various brands
Title: Re: reinvent the wheel
Post by: Glenn R on May 28, 2010, 10:23:01 AM
OH, Its making so much sense now!!!  The wheels are starting to turn much quicker now.

copious amounts of bourbon help lubrication David.

Hear, hear! Seconded.

copious amounts of bourbon help lubrication David.
Funny you should say that, I had a good long chat with a mutual friend about various brands

Yes it was a good chat, especially on the relative merits of the different brands.

BTW Duh, you will see some Extension dictionary and Xrecord usage in that XrefStates application I posted to 'tool of the month' for another example.
Title: Re: reinvent the wheel
Post by: David Hall on May 28, 2010, 11:32:10 AM
Very cool stuff.  Lots to study..... My brain hurts
Title: Re: reinvent the wheel
Post by: David Hall on July 09, 2010, 12:38:54 PM
OK, Next question-  What is the proper way to store an XRecord to a drawing as a whole?  Should I use the NOD of the drawing or create my own dictionary?
Title: Re: reinvent the wheel
Post by: David Hall on July 09, 2010, 12:45:23 PM
Glenn, I am studying your code from the plugin, and it looks like you are writing the XRecords in the current dwg db, is that right?
Title: Re: reinvent the wheel
Post by: Glenn R on July 09, 2010, 01:46:01 PM
Duh,

There's no other place to write them to really, or did you mean that I'm writing them to drawing objects and NOT the land of NOD?

If so, then yes, in XrefStates I wrote them to each blockTableRecord that was an xref. That way, AutoCAD handles the redundancy for me eg. when an xref is detached, the BTR is no longer there, so I don't have to update a master list somewhere else and possibly run the risk of having it get out of sync.

Make sense?
Title: Re: reinvent the wheel
Post by: David Hall on July 09, 2010, 01:50:01 PM
makes sense, and I think you answered my question.  I need to figure out another way to store the number
Title: Re: reinvent the wheel
Post by: dgorsman on July 09, 2010, 01:54:56 PM
For drawing-level data, I create an application-specific dictionary under the NOD.  If necessary, I add another layer or two of dictionaries under that, just to keep the XRECORDS organized.  Object-specific data works the same way, with the application-specific dictionary located under the objects extension dictionary.  This way I don't accidentally hose another applications data, reduces the chance of others buggering with mine, and it keeps my own data organized.
Title: Re: reinvent the wheel
Post by: David Hall on July 10, 2010, 12:30:59 PM
I was thinking that either I will have to use an attribute to store the width factor, or figure out some other way.