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.
#83569 by dhs
Fri Apr 25, 2025 12:52 am
I am hoping that I might find at least a couple of people who would be willing to look at a beta version of a new Shadow macro. I am obviously keen to know about any bugs found, but also interested in feedback on the functionality or user interface (I think the interface is pretty friendly, and hoping that the brief instructions I have written are adequate for the average person to use it confidently, but others may have a different view).

I was prompted to write the new version when a user found a bug in the old version a few months ago. Initially I was intending to simply convert the existing code from DCAL Classic to D4D, but finding things that didn't work in D4D set me off on more of a re-write job (even though Mark fixed the main issue I had pretty promptly ... adding voids to polylines in D4D which I had already coded in an alternate fashion).

The new macro will not run on DataCAD versions earlier earlier than 23.00.03 (it uses functionality introduced in that version), but offers significant improvements over the old version:

- runs very much faster
- produces a single outline of shadows, optionally with fills of various levels of opacity
- can process multiple surfaces in one operation
- allows processing of up to 4 clock times and 4 dates in one operation (total of up to 16 date/time combinations)
- Sun's Eye View that can step through time in 1 minute increments (up to 1 hour increments)

I have not done anything to process smart entities at this stage (I have never used them - I stopped using DataCAD seriously long before they were introduced) ... I am interested into looking into this if anybody out there would care to share a drawing with me that uses smart entities (so I have something sensible to test with ... Dcad used to come a sample drawing or 2, but I can't find any samples in the latest install).

If anybody here is interested in looking at the macro in it's current state I would certainly appreciate any comments. It can be downloaded from https://dhsoftware.com.au/downloads/ShadowMacro_2.0.0.0.zip

Out of interest, I am usingClipper2 library (by Angus Johnson) to perform polygon union operations. I looked at that initially, but found a bug quite quickly in my testing (and started to write my own union logic), but re-evaluated it after Angus produced a fix within a week of me reporting the bug. It seems to be pretty solid in my testing now, but I admit that I am a little nervous about it given how quickly I found the initial problem. Still it is much more mature and better tested than anything I could write myself so as I have not found any other bugs myself I decided to go with it.
I am passing point co-ordinates to Clipper2 using Integer64 values, rounded to the nearest 1/137438953472th of an inch (Datacad's 1/32" units divided by 2^32). I do not expect the introduced inaccuracies to be in any way significant.

Thanks,
David H.
#83599 by dhs
Tue May 20, 2025 3:00 pm
I think I am extremely close to the final release version of my new Shadow macro, and would be grateful if anybody was able to download and test it out.
I have introduced processing of Smart Entities in this version (Walls/Windows/Doors are supported). The macro has only been tested by 2 people (that I know of) and I don't believe the Smart Entity Processing has been tested at all (apart from some extremely basic testing I have done), so would be particularly grateful if anybody could provide feedback on using Smart Entities (or if anybody could share a drawing I could use for testing these more extensively).
I have also included a more detailed instruction manual in this version (Shadow.pdf in the attached zip, or copy this pdf to your macro folder and select S9 from the macro main menu to access it)

I have removed the previous attachment to this post - please upload the attachment in the following post.

Source code for this macro is in my Bitbucket workspace as usual (you will need the new-Shadow and Common repositories, and will most likely need to change paths to the D4D header files as I have a fairly unique folder structure for these)

Regards,
David H
Last edited by dhs on Fri May 23, 2025 2:05 pm, edited 1 time in total.
#83606 by dhs
Fri May 23, 2025 2:04 pm
I have made a couple of pretty minor changes to the macro:
  1. Fixed trimming of line shadows (i.e. shadows cast of entities such as 3d lines/arcs, or of 2d lines/arcs where the z-base and z-hite are equal). These shadows are created as 3d lines, and the fix is to correctly cut out any sections of these lines that overlap polyline shadows.
  2. Added a cover to the polyline(s) that are created for shadows of entities that have a non-zero area

Thanks,
David H.
Last edited by dhs on Sat May 24, 2025 3:19 am, edited 1 time in total.
#83608 by dhs
Sat May 24, 2025 3:18 am
It seems a pretty major bug has crept into the code in the last few builds ... it seems not create correct shadows on anything but a level surface :?
Any comments on the interface would be welcome, but no real point testing the2.0.0.10 version any further (I'll remove the download from my previous post, and post a new version when that problem is fixed).
Thanks,
David H.
#83609 by dhs
Sat May 24, 2025 3:32 am
... looks like the problem I referred to above was caused by selecting the same polygon as both the surface to cast shadows onto and as one of the entities to cast shadows of. I need to do a bit more investigation, but hopefully a test to prevent that happening is the only fix required ...
#83610 by dhs
Sat May 24, 2025 12:48 pm
New version available with the following change:
Whilst you can still select a polygon as both a shadow surface and an entity to cast shadows, a surface will never cast a shadow onto itself (so in the case where you select multiple surfaces and one of those is also a casting entity, that entity will cast shadows onto the other surfaces but not onto itself)

The file previously attached to this post has been removed as a more up-to-date file is included in a subsequent reply.
Last edited by dhs on Sat Jun 07, 2025 4:25 pm, edited 1 time in total.
#83611 by dhs
Sun May 25, 2025 12:36 pm
I think I am extremely close to the final release

... obviously not quire as close as I thought: ... Pretty close, but not extremely.

A couple of significant bugs have come out of testing, and a couple of suggestions for new features or fine-tuning of the interface. Thanks to those who provided feedback.

I've identified the causes of the identified bugs, and it shouldn't take me all that long to fix them. But I'm going to take a week or 2 to fix and test before making another beta available.

Thanks,
David H
#83633 by dhs
Sat Jun 07, 2025 4:23 pm
A new beta version of my Shadow macro is now available:

(download removed as there is now a later version available)
I would welcome any comments, bug reports etc. from anybody who takes the time to download the above file and try the macro out.

There are a number of bug fixes, changes and added functions since the previous version, with the main changes summarised below:

  • Fixed a bug where sometimes no shadows were created. This was caused by my applying a transformation matrix that sometimes resulted in the casting entities being below z-zero. Ironically this was more likely to happen in my own Southern Hemisphere (where the sun direction was more likely to be from the top of the screen (north)).
  • Fixed a bug where incorrect shadows could be generated if in fact the entire surface was shaded by the casting entities.
  • After creating shadows, set active layer back to what it was before creating them.
  • Added a 2D Shadow option. This is used to create a 2D shadow diagram from a previously generated 3D shadow. The most likely use of this would be to create a shadow to show on an elevation.
  • Separated the Outline and Fill options on the Create Shadow Form. Previously there was a single field where you could select from some pre-defined combinations (in 10% fill opacity increments). There are now 2 fields: The first allows you to select the outline type (3D lines, Visible Polyline, or No Outline), and the second allows you to specify Fill Opacity (Fill is not available with 3D lines, can be set to zero to create polylines with no fill, and has a minimum opacity of 1% when used with the 'No Outline' option).
  • Fixed an issue where areas could be reported incorrectly on the Report Option (could happen for dates/times which followed unselected dates/times if not all dates/times were selected).
  • Added an 'Identify' option. This is used to display information about a previously created shadow (location, date, time etc.)
  • Various minor changes and fixes to the Suns-Eye view options (e.g. prevent it displaying a view when the sun was at a very low altitude or below the horizon, prevent it crashing if no casting entities were selected, automatically display the view if only one date and time have been selected).
  • Added the ability to create shadows directly from a Suns-Eye view.
  • Added a confirmation dialog if Clear Layer option is selected when creating shadows. This dialog has 3 options ('Do Nothing' (i.e. don't clear), 'Clear Shadow Entities ONLY', or 'Clear ALL entities'). Note that the dialog will appear once only if you have selected to clear multiple layers (and the selection will apply to all the layers that are to be cleared).

I plan to create a video demonstrating the macro over the coming days.

Thanks,
David H.
Last edited by dhs on Wed Jul 02, 2025 5:38 pm, edited 1 time in total.
#83698 by dhs
Sat Jun 21, 2025 5:12 pm
I plan to create a video demonstrating the macro over the coming days.

Just a quick follow up on this as it is now a couple of weeks since I indicated a video in "the coming days". There are a few reasons for the delay:
  • I didn't really have a good model to demonstrate all the functionality that I wanted to show ... I've never done much 3D modelling in DC, so it took me a few days to create something suitable to use (I learnt a bit in the process) ...
  • My macro did not cater for voids in surface polygons, but I realised that it would be good to include this functionality (didn't take long to add, but then testing and finetuning all took time)
  • I found a bug in my logic that trims the shadow to the area of the surface. A pretty obscure set of circumstances (involves a scenario where a vertex of the shadow polygon touches an edge of the surface polygon, but neither that vertex nor adjoining shadow vertexes are actually inside the surface polygon, even though some other vertexes are inside the surface).
    I had written my own logic for to trim the shadow to the surface, but since I already had Angus Johnson's Clipper library in the project I thought I might as well use that functionality instead ...
    I now have some issues with the Clipper logic which are ongoing (may revert back to my own code). The issues are with voids which occasionally are not accounted for correctly in the trimmed result (mostly they are correct, but not always). I believe the issue is caused by the way my macro treats voids as part of the polyline outline (with 'sides' connecting the void to the outline )... I started down this path before Mark fixed the polyline void functionality, so need to decide if I want to continue with that or rewrite all the void logic logic in a more conventional way ... will probably take some time.
  • While investigating the trimming bug I added a macro option to treat the surface as infinite (i.e. the macro uses 3 points from the polygon to define an infinite surface). I will leave this as a new option in the macro
So the bottom line is that it could be a little while before I have another beta version available.

Regards,
David H.

.
#83716 by dhs
Wed Jul 02, 2025 5:35 pm
A new version of this macro is now available:

(download removed as a later version is available in a subsequent post)

I have done reasonably extensive testing myself and am not aware of any remaining problems. I have not received any feedback from others since late May, so not sure how well it has been tested by others (if at all), but I am fairly confident with this latest version. There are still some enhancements I can think of, but they will be for subsequent versions once the current functionality is released (I would be pleased to receive any suggestions for enhancements from others).

The main changes that have been made since the previous version are summarised below:
  • Added ability to save 2D shadows as polygons as an alternative to polylines (for shadows with up to 256 vertices)
  • Fixed an occasional problem that could occur when casting shadows onto polygon surfaces with void(s) - I am now using the Clipper library for this functionality
  • Re-evaluate a matrix if required for each date and time processed. For efficiency I was previously calculating a matrix for each surface and then using that matrix for all date/time combinations. This was fine for surface that were more or less horizontal, but did not take into account the fact that for vertical surfaces the sun could move from one side of the surface to the other during the day.
  • Add option to ignore voids (or not) for both surface and casting entities
  • Some further logic to simplify shadows where possible. It will now merge multiple polylines into a single polyline for most surfaces, and if an outline type of 'Lines' is selected then most if not all lines internal to the shadow are eliminated (including lines along edges of adjoining surface polygons within the shadow)

Thanks,
David H.
Last edited by dhs on Thu Jul 03, 2025 1:45 pm, edited 1 time in total.
#83718 by Mark F. Madura
Thu Jul 03, 2025 8:27 am
Hi David,

I had a little trouble getting the macro setup in the last build but got it worked out. In this build, I can't seem to get the shadows working. The report indicates the sun is too low at 12 noon on Jun 21st.

I've attached my test file for Hartford, CT USA.

dhShadow_Test
(12.4 KiB) Downloaded 17 times

MFM
#83722 by dhs
Thu Jul 03, 2025 1:42 pm
The report indicates the sun is too low at 12 noon on Jun 21st.

Thanks for the feedback Mark. You're the first Western Hemishpere person to provide feedback (first non-Australian actually).

There was an error in the logic that parsed the time-zone string, resulting in the macro using a timezone of +4 hours (instead of -4 hours) for Hartford. This has been fixed in the version below:

(1.87 MiB) Downloaded 23 times

Regards,
David H.
#83730 by dhs
Fri Jul 04, 2025 3:17 pm
All seems to be working correctly now

Thanks Mark. Glad it was a very easy fix.

Bit of an embarrassing mistake on my part though: For the Timzone string (e.g. 'UTC-4:00') I was using string.substring with a startindex of 4 to check for the negative sign (should have been 3 since startindex is zero based). Not sure how I managed to get that wrong (I had used the correct zero-based indexes in several other places in the same function), although it can be confusing as traditional Delphi uses a 1 based index for strings.

Who is online

Users browsing this forum: No registered users and 2 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