Update Code_2_7.py
Browse files- Code_2_7.py +43 -36
Code_2_7.py
CHANGED
|
@@ -8,43 +8,52 @@ Original file is located at
|
|
| 8 |
"""
|
| 9 |
|
| 10 |
"""## Imports"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
import numpy as np
|
| 13 |
import cv2
|
| 14 |
from matplotlib import pyplot as plt
|
| 15 |
-
import math
|
| 16 |
-
from PIL import Image , ImageDraw, ImageFont , ImageColor
|
| 17 |
-
import fitz
|
| 18 |
-
import ezdxf as ez
|
| 19 |
-
import sys
|
| 20 |
-
from ezdxf import units
|
| 21 |
-
# from google.colab.patches import cv2_imshow
|
| 22 |
-
from ezdxf.math import OCS, Matrix44, Vec3
|
| 23 |
-
import ezdxf
|
| 24 |
-
print(ezdxf.__version__)
|
| 25 |
-
import matplotlib.pyplot as plt
|
| 26 |
from matplotlib.patches import Polygon
|
| 27 |
from shapely.geometry import Point, Polygon as ShapelyPolygon
|
| 28 |
-
from
|
| 29 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
import pandas as pd
|
| 31 |
import google_sheet_Legend
|
| 32 |
-
|
| 33 |
-
from ezdxf import bbox
|
| 34 |
-
from math import sin, cos, radians
|
| 35 |
-
# from ezdxf.tools import rgb
|
| 36 |
-
from ezdxf.colors import aci2rgb
|
| 37 |
-
# from ezdxf.math import rgb_from_color
|
| 38 |
-
from collections import Counter
|
| 39 |
|
| 40 |
-
import xml.etree.ElementTree as ET
|
| 41 |
from PyPDF2 import PdfReader, PdfWriter
|
| 42 |
-
from PyPDF2.generic import
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
from
|
| 46 |
-
from ctypes import sizeof
|
| 47 |
-
from io import BytesIO
|
| 48 |
|
| 49 |
|
| 50 |
|
|
@@ -411,12 +420,10 @@ def save_multiple_annotations_bax(annotations, output_path, column_order,pdfWidt
|
|
| 411 |
Resource = SubElement(GlobalResources, 'Resource')
|
| 412 |
SubElement(Resource, 'ID').text = scale
|
| 413 |
SubElement(Resource, 'Raw').text = '789c85d04f0b82401005f0af3247bd34a35176b085503c55847f22a80e2a4b7858ad7537e8dba7951ea2a5e330efc783e7fb983eae1c373c6fb5e498e842f577bcc6d872a014b00407848d87e310dd6a5170193552e40a33abfb0540139ace5ccff316188243844962d98c9d3134b297eba2f4255626d1dee06d3e200a4149cd47989ae0c99dd32fb8ebe0a8f7265dea3fb5b9bc7095d5950a9aface655b3575bf070d8b30f604438f6873'
|
| 414 |
-
|
| 415 |
-
with open(output_path, 'w', encoding='utf-8') as f:
|
| 416 |
-
f.write(pretty_xml)
|
| 417 |
|
| 418 |
-
print(f" Saved {len(annotations)} annotations to {output_path}")
|
| 419 |
-
return
|
| 420 |
|
| 421 |
"""PDF to image"""
|
| 422 |
|
|
@@ -2249,7 +2256,7 @@ def mainFunctionDrawImgPdf(datadoc,dxfpath, dxfratio,SearchArray,Thickness,pdfpa
|
|
| 2249 |
# save_multiple_annotations_bax(
|
| 2250 |
# bax_annotations, 'Area_Perimeter_OMAR_output.bax', column_order, pdfWidth, pdfHeight
|
| 2251 |
# )
|
| 2252 |
-
save_multiple_annotations_bax(
|
| 2253 |
annotations, '2552 Page 1.bax', column_order, pdfWidth, pdfHeight
|
| 2254 |
)
|
| 2255 |
|
|
@@ -2274,10 +2281,10 @@ def mainFunctionDrawImgPdf(datadoc,dxfpath, dxfratio,SearchArray,Thickness,pdfpa
|
|
| 2274 |
|
| 2275 |
column_xml = generate_bluebeam_columns_raw(column_order)
|
| 2276 |
|
| 2277 |
-
|
| 2278 |
-
|
| 2279 |
|
| 2280 |
-
|
| 2281 |
|
| 2282 |
|
| 2283 |
if pdf_content:
|
|
@@ -2309,6 +2316,6 @@ def mainFunctionDrawImgPdf(datadoc,dxfpath, dxfratio,SearchArray,Thickness,pdfpa
|
|
| 2309 |
x,y,z=int(annot_color.get(v)[0]*255),int(annot_color.get(v)[1]*255),int(annot_color.get(v)[2]*255)
|
| 2310 |
list1.loc[len(list1)] =[annot.info['content'],annot.info['id'],annot.info['subject'],[x,y,z]]
|
| 2311 |
print('LISTTT',list1)
|
| 2312 |
-
return doc2,latestimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas
|
| 2313 |
|
| 2314 |
|
|
|
|
| 8 |
"""
|
| 9 |
|
| 10 |
"""## Imports"""
|
| 11 |
+
import sys
|
| 12 |
+
import math
|
| 13 |
+
import random
|
| 14 |
+
import string
|
| 15 |
+
import zlib
|
| 16 |
+
import base64
|
| 17 |
+
import datetime
|
| 18 |
+
import uuid
|
| 19 |
+
import re
|
| 20 |
+
from io import BytesIO
|
| 21 |
+
from ctypes import sizeof
|
| 22 |
+
from collections import Counter
|
| 23 |
+
from typing import NewType
|
| 24 |
+
import xml.etree.ElementTree as ET
|
| 25 |
+
from xml.etree.ElementTree import Element, SubElement, tostring, ElementTree
|
| 26 |
+
from xml.dom.minidom import parseString
|
| 27 |
|
| 28 |
import numpy as np
|
| 29 |
import cv2
|
| 30 |
from matplotlib import pyplot as plt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
from matplotlib.patches import Polygon
|
| 32 |
from shapely.geometry import Point, Polygon as ShapelyPolygon
|
| 33 |
+
from shapely.ops import unary_union
|
| 34 |
+
from PIL import Image, ImageDraw, ImageFont, ImageColor
|
| 35 |
+
|
| 36 |
+
import fitz
|
| 37 |
+
import ezdxf
|
| 38 |
+
from ezdxf import units, bbox
|
| 39 |
+
from ezdxf.colors import aci2rgb
|
| 40 |
+
from ezdxf.math import OCS, Matrix44, Vec3, Vec2
|
| 41 |
+
|
| 42 |
import pandas as pd
|
| 43 |
import google_sheet_Legend
|
| 44 |
+
import tsadropboxretrieval
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
|
|
|
| 46 |
from PyPDF2 import PdfReader, PdfWriter
|
| 47 |
+
from PyPDF2.generic import (
|
| 48 |
+
NameObject,
|
| 49 |
+
TextStringObject,
|
| 50 |
+
DictionaryObject,
|
| 51 |
+
ArrayObject,
|
| 52 |
+
FloatObject,
|
| 53 |
+
NumberObject,
|
| 54 |
+
)
|
| 55 |
|
| 56 |
+
from math import sin, cos, radians, isclose
|
|
|
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
|
|
|
|
| 420 |
Resource = SubElement(GlobalResources, 'Resource')
|
| 421 |
SubElement(Resource, 'ID').text = scale
|
| 422 |
SubElement(Resource, 'Raw').text = '789c85d04f0b82401005f0af3247bd34a35176b085503c55847f22a80e2a4b7858ad7537e8dba7951ea2a5e330efc783e7fb983eae1c373c6fb5e498e842f577bcc6d872a014b00407848d87e310dd6a5170193552e40a33abfb0540139ace5ccff316188243844962d98c9d3134b297eba2f4255626d1dee06d3e200a4149cd47989ae0c99dd32fb8ebe0a8f7265dea3fb5b9bc7095d5950a9aface655b3575bf070d8b30f604438f6873'
|
| 423 |
+
bax_xml= tostring(doc, encoding="unicode", method="xml") #tostring(doc, encoding="utf-8", method="xml").decode("utf-8")
|
|
|
|
|
|
|
| 424 |
|
| 425 |
+
# print(f" Saved {len(annotations)} annotations to {output_path}")
|
| 426 |
+
return bax_xml
|
| 427 |
|
| 428 |
"""PDF to image"""
|
| 429 |
|
|
|
|
| 2256 |
# save_multiple_annotations_bax(
|
| 2257 |
# bax_annotations, 'Area_Perimeter_OMAR_output.bax', column_order, pdfWidth, pdfHeight
|
| 2258 |
# )
|
| 2259 |
+
bax_xml=save_multiple_annotations_bax(
|
| 2260 |
annotations, '2552 Page 1.bax', column_order, pdfWidth, pdfHeight
|
| 2261 |
)
|
| 2262 |
|
|
|
|
| 2281 |
|
| 2282 |
column_xml = generate_bluebeam_columns_raw(column_order)
|
| 2283 |
|
| 2284 |
+
# with open("2552 Page 1.xml", "w", encoding="utf-8") as f:
|
| 2285 |
+
# f.write(column_xml)
|
| 2286 |
|
| 2287 |
+
# print(column_xml)
|
| 2288 |
|
| 2289 |
|
| 2290 |
if pdf_content:
|
|
|
|
| 2316 |
x,y,z=int(annot_color.get(v)[0]*255),int(annot_color.get(v)[1]*255),int(annot_color.get(v)[2]*255)
|
| 2317 |
list1.loc[len(list1)] =[annot.info['content'],annot.info['id'],annot.info['subject'],[x,y,z]]
|
| 2318 |
print('LISTTT',list1)
|
| 2319 |
+
return doc2,latestimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas, bax_xml, column_xml
|
| 2320 |
|
| 2321 |
|