The DataCAD Developer Network (DDN) is an online resource for information and support for DCAL® (DataCAD Applications Language) developers as well as anyone interested in creating fonts, toolbars, hatch patterns, or linetypes for use in DataCAD.
#75670 by dhs
Sun Feb 10, 2019 4:19 am
Hi,
I'm wondering if anybody can offer advice as I'm getting pretty frustrated trying to work out what I am doing wrong in the following code:
Code: Select all  // create a new polyline based on the NewLines list
  ent_init (pln, entpln);
  for i := 0 to NewLines.Count-1 do begin
    NewLine := NewLines[i];
    polyvert_init (pv);
    pv.shape := NewLine.shape;
    if pv.shape = pv_vert then begin
      pv.bulge := 0.0;
      pv.pnt := NewLine.pt1;
      pv.nextpnt := NewLine.pt2;
    end
    else begin
      arc_to_bulge (NewLine.cntr, NewLine.rad, NewLine.bang, NewLine.eang, NewLine.ccw,
                    pv.pnt, pv.nextpnt, pv.bulge);
    end;
    polyvert_add (pv, pln.plnfrst, pln.plnlast);
  end;

  pln.plnclose := true;
  ent_add (pln);

This is part of a function that produces a new polyline by offsetting an existing polyline. Subsequent logic does an ent_draw of the created pln entity and it is being drawn exactly as expected. But ...
  • if I redraw the screen (using 'u' key) the polyline disappears (refreshing from DL using 'Esc' does not cause it to disappear)
  • every entity that I create on the same layer after the creation of this polyline behaves the same way (i.e. disappears if the screen is redrawn). If I change to another layer then entities can be created as normal (they do not dissapear with a redraw).
  • if I delete and then restore subsequent entities on the layer (using ',' then '.') then they are drawn on the screen again, but disappear if I press 'u' to redraw the screen
  • If I delete all subsequent entities and then press '<' to delete the group containing the polyline then I get 'DataCAD (internal diagnostics) fault 28 Error from: XXX' (where XXX varies ... I have seen values of 736, 73, 77)
  • If I delete all subsequent entities and then press ',' to delete just the polyline then it is deleted and pressing '.' will restore it and draw it on the screen. What's more, mostly if I redraw the screen after deleting and then restoring the polyline then everything is back to normal (the polyline together with any subsequent entities that have been deleted and then restored are shown on the screen correctly by a redraw, also any new entities that are subsequently added do not disappear on a redraw). I say 'mostly' because at least once when I tested this everything has not been back to normal
There is nothing in any subsequent logic that does anything to update the created pln .
I have tested this in Both DataCAD 20 & 21. I was initially building this using the Header Files supplied with DataCAD 17, but have now tried it with both the DataCAD 20 & 21 header files with the same result

As far as I can see, the logical steps that create this polyline are the same as I have used to create polylines elsewhere ( i.e. ent_init followed by a series of polyvert_init and assigning values to the pv fields before doing a polyvert_add and finally set plnclose and do an ent_add). None of the other polylines created by these same logical steps have this problem.
I tried adding an ent_add immediately after the ent_init and an ent_update after each polyvert_add (and changing the existing ent_add to an ent_update), but this did not change the symptoms.

I have debugged this logic processing a simple rectangular polyline and confirmed that all the points added have valid initialized x, y, & z values and in the example I debugged then shape was zero (pv_vert) in every case. Can't think what else to check.

I'm probably missing something blatantly obvious, but if anybody can offer any guidance then I would be most grateful.
#75671 by dhs
Sun Feb 10, 2019 4:59 pm
I still have the problem, but can report on a few other things I have tried:

Mostly I have been able identify the entity and it does not show anything unusual (one time I got fault 301 from 736 trying to identify the polyline, but I have not been able to reproduce that). I can also measure the polyline (before it disappears) and it returns correct area, perimeter, volume with no obvious problems.

It now seems that the problem is not actually in the code I posted. That code is in a function with the following definition:
Code: Select allFUNCTION OffsetPln (orig_pln : entity;
                    var pln  : entity;
                    OffsLeft : boolean;  // if sense is anti-clockwise then true will be to inside, false will be outside
                    offsdist : double) : boolean;

I tried placing the following at the very beginning of the function:
Code: Select all  ent_copy (orig_pln, pln, true, false);
  result := true;
  exit;

The above code simply copies the source polyline and then exits, yet the same problem still exists with the copied polyline. The source polyline displays correctly on a redraw (so I can't tell if the copied one displays or not), but entities added subsequently disappear on a redraw.

I also tried setting the pln address to nil with the following lines at the very beginning of the function:
Code: Select all  setnil (pln.addr);
  result := true;
  exit;

This fixed the problem (the original polyline and all subsequent entities displayed correctly on a redraw, but obviously I'm missing the polyline that I want).
The only subsequent logic that does anything with the created entity is as follows (l^.ent2 is the entity which was passed to the OffsetPln function as the var ply parameter)
Code: Select all  if l^.doFill then begin
    atr := InitSolidFillAttribute (l^.FillColours[1], 0, 0);
    atr.SPBvisible := l^.doFillOutline;
    if (not l^.DefineByCenter) or (not l^.CreateAtCenter) or (not l^.FillInner) then
      atr_add2ent (l^.ent, atr)
    else if not isnil (l^.ent2.addr) then
      atr_add2ent (l^.ent2, atr)
  end;

... <snip> ...

  if not isnil (l^.ent2.addr) then begin
    ent_update (l^.ent2);
    ent_draw (l^.ent2, drmode_white);
  end;

I have tested with l^.Fill being both true and false (fill is added correctly if it is true).
The only possible problem I could see was that ent_update is called when no changes have been made (not that I would expect that to be a problem). I tried removing the ent_update but that made to difference.

Out of desperation I also tried using l^.ent2 directly in the OffsetPln function (instead of using the var pln parameter). Couldn't see why this would help (and it didn't), but am at a point where I would try anything.

At this stage all I seem to have done is eliminated any possible causes in the code I have posted. So I'm not really hopeful that anybody will be able to help, but I would be pleased to receive any suggestions ...
#75677 by dhs
Mon Feb 11, 2019 1:38 pm
ok, I found the problem:

I had the following logical steps in my code:
  1. Create Ent1
  2. if Option Selected then Create Ent2 (the polyline created by the code I posted earlier)
  3. Do some processing on Ent1 and add some attributes to it
I did not expect it to be a problem, but it appears that adding another entity between steps 1 and 3 caused my issues (The issue did not occur if the Option tested in step 2 was not selected).
All the fields in Ent1 were still correct, but it seems that it is necessary to read it from the database again due to having created another entity in the intervening steps. The issue appears to be fixed by adding the step shown below:
  1. Create Ent1
  2. Create Ent2 (the polyline created by the code I posted earlier)
  3. Read Ent1 from the database again ( i.e. ent_get(Ent1, Ent1.addr) )
  4. Do some processing on Ent1 and add some attributes to it

Who is online

Users browsing this forum: No registered users and 14 guests

About DataCAD Forum

The DataCAD Forum is a FREE online community we provide to enhance your experience with DataCAD.

We hope you'll visit often to get answers, share ideas, and interact with other DataCAD users around the world.

DataCAD

Software for Architects Since 1984